itsfadnis / fetch-interceptor Goto Github PK
View Code? Open in Web Editor NEWIntercept fetch requests
Home Page: https://itsfadnis.github.io/fetch-interceptor
Intercept fetch requests
Home Page: https://itsfadnis.github.io/fetch-interceptor
Hi, i was looking for angular Http interceptor alike code, for my react-native project and found this package. As i am new to react-native so having some problem while implementing this package on my project.
I have followed the doc an implemented it in my code. Now the thing is being not able to modify the error message when it request or response fails.
How can i make the re-use of "fetch-interceptor" across multiple files.
Didn't find any guide for implementing AbortSignal as i was happy to see that this package is also loaded with AbortController but failed to use it.
Any kind of info would be of much help. thanks.
Now, the onRequestFailure function is called when the response.ok
is false. index.js#L127
However, when a network error occurred, fetch promise will reject. Perhaps we should call the onRequestFailure function when fetch promise rejects.
So based on your documentation i added the following to my application. as you can see i just added simple console statements to prove it was working. i get the "onBeforeRequest" and nothing else. In my case i watch to catch all 401 but based on this example thats not going to work. As a result im going to uninstall but i wanted to give you feed back before i did.
import FetchInterceptor from 'fetch-interceptor'
// Register interceptor hooks
const interceptor = FetchInterceptor.register({
onBeforeRequest(request, controller) {
// Hook before request
console.log("onBeforeRequest")
},
onRequestSuccess(response, request, controller) {
// Hook on response success
console.log("onRequestSuccess")
},
onRequestFailure(response, request, controller) {
// Hook on response failure
console.log("onRequestFailure")
}
});
// Make fetch requests to see interceptor in action
fetch('http://whatever.com/whatever');
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.