Package Exports
- fetch-intercept
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fetch-intercept) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
fetch-intercept
Interceptor library for the native fetch command inspired by angular http interceptors.
Note: Current only browser environments are supported.
Installation
npm install fetch-intercept --saveUsage
Make sure you have a fetch compatible browser or added a appropriate polyfill.
import fetchIntercept from 'fetch-intercept';
const unregister = fetchIntercept.register({
request: function (url, config) {
// Modify the url or config here
return [url, config];
},
requestError: function (error) {
// Called when an error occured during another 'request' interceptor call
return Promise.reject(error);
},
response: function (response) {
// Modify the reponse object
return response;
},
responseError: function (error) {
// Handle an fetch error
return Promise.reject(error);
}
});
// Call fetch to see your interceptors in action.
fetch('http://google.com');
// Unregister your interceptor
unregister();License
MIT