Skip to content

Instantly share code, notes, and snippets.

@GriffinHeart
Last active June 2, 2016 09:20
Show Gist options
  • Save GriffinHeart/4b97dc0a8a0f8a13c315859be980c1c0 to your computer and use it in GitHub Desktop.
Save GriffinHeart/4b97dc0a8a0f8a13c315859be980c1c0 to your computer and use it in GitHub Desktop.
// Fetcher file
const handleErrors = async (...myargs) => {
const response = await originalFetch(...myargs);
if (!response.ok) {
throw Error(response.statusText);
}
return response;
};
// fetch file
function localFetch(url, options) {
console.log('--------------url=========');
console.log(url);
console.log('--------------options=========');
console.log(options);
return fetch(localUrl(url), options);
}
export { localFetch as default, Request, Headers, Response };
// If I run this like it is the output is:
Thu, 02 Jun 2016 08:09:03 GMT server:fetch.server --------------url=========
Thu, 02 Jun 2016 08:09:03 GMT server:fetch.server { exports: { default: [Function: Fetcher] }, id: 124, loaded: true }
Thu, 02 Jun 2016 08:09:03 GMT server:fetch.server --------------options=========
Thu, 02 Jun 2016 08:09:03 GMT server:fetch.server { default: [Function: Fetcher] }
// If I add a console.log(args) in handleErrors then the output is correct:
Thu, 02 Jun 2016 08:08:50 GMT server:fetch.server --------------url=========
Thu, 02 Jun 2016 08:08:50 GMT server:fetch.server //127.0.0.1:9393/api/v1/login
Thu, 02 Jun 2016 08:08:50 GMT server:fetch.server --------------options=========
Thu, 02 Jun 2016 08:08:50 GMT server:fetch.server { headers: { contentType: 'application/json', Authorization: 'Bearer undefined' }, method: 'post', body: '{"username":{"username":"
bleh@bleh.com","password":"password"}}' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment