resolve requests immediately on request interceptor?
See original GitHub issueSummary
I’m using a global request interceptor. I want to be able to decide whether to send the request or to resolve them with a particular data immediately from the interceptor (or maybe else where).
Snipet
axios.interceptors.request.use(config => {
if (shouldNotSend) {
// I don't want to continue sending this request
// instead I want to resolve this immediately
return Promise.resolve(data);
}
return {
...config,
headers: {
...config.headers,
customHeader: 'custom header value'
}
};
});
Context
- axios version: 0.18.0
- Environment: node v10.5.0, chrome 67.0.3396.99, MacOS High Sierra 10.13.5
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:13
Top Results From Across the Web
How to Implement a Request Interceptor Like Axios
Step 1: Interceptor manager · Step 2: Wrap the fetch · Step 3: Intercept the request · Step 4: Test the interceptors.
Read more >Axios: How to intercept and respond to axios request
Here's how i was able to resolve the problem axios.interceptors.request.use( request => { if (localResponse) { throw { isLocal: true, ...
Read more >Setting up Axios Interceptors for all HTTP calls in an application
Interceptors are a feature that allows an application to intercept requests or responses before they are handled by the .then() or the .catch() ......
Read more >4 ways to use Axios interceptors | Khaled Garbaya
Log every request and response using interceptors. Logging requests can be beneficial, especially when you have a large app and you don't know ......
Read more >Intercepting Requests & Responses Using Axios
In short, you can intercept the requests or responses before they are handled by then or catch.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I made it with adapter. If there is some redis cache - api get cached data, otherwise starts real request.
I want to conditionally either return custom data (from a redis cache) or perform the request. Do I do this with an interceptor or an adapter?