How could I ignore forward handle function wrote in catch or then when I do something in response of Vue.http.interceptors?
@steffans
Can you explain this with an example? I guess you mean your interceptor would provide a response and the client handle function will be skipped ?
Yeah, but more exact is that interceptor will head off the res and the whole process ends now.
It is like filter and interceptor of J2EE.
So, for the present situation, Vue.http.interceptors is more like Decorator.
I know Promise.resolve() and Promise.reject(), but I am not sure it is what I want.
Anybody here?
@steffans Where are you?
Please, nobody until now?
@zyf0330 Yes, it's kind of a decorator right now. The only way to modify the interceptor chain result is to set the client property on the request (like the JSONP interceptor). This will replace the main function which is called after all request interceptors have run and before the response interceptors. It would be great to have something to stop the request at anytime and return a response. As you mentioned Promise.reject() could work and then the rejection value has to be be a response object. Do you have any other idea? I will also think about a good solution for this.
Happy to see you after about two months, I just thought this place was abandoned. Ha!
I was writing something about Page Request Cache yesterday, and relift this question. Then, I read source code and inject some code into the eighth part HTTP. At the same time, I know how it runs.
In fact, I thought it is truly a Interceptor before I know it, but now, I suggest you change its name to Decorator unless you make it a factly Interceptor, which can interrupt request.
Start with claiming, here is about changing request process, not canceling it. Now, we talk about JSONP interceptor. Actually, it is a little special, I think. Because it is a kind of Request Way like get or post, but it is implement by interceptor. What I want to do, is also change process, to fetch resource from cache not network. So we need a way to custom Request Way, agree? And I have thought about it, it doesn't break gist of vue-resource which is to fetch resource.
As for detail to implement, I don't have too much experience. I may only say some piece. It can provide a constructor to generate a client, and developer can give it a function to return data of response and something else.
Hope to help you. And happy to see you coming.
@zyf0330 We built a resource cache interceptor, where we skip the HTTP request when we have a hit. Take a look here: https://github.com/pagekit/pagekit/blob/develop/app/system/app/lib/resourceCache.js
Actually, after I finish it , I doubted that if it is necessary. You know, there is one thing called 304.
Refactored interceptors which now supports returning a response instead of moving on with the next interceptor.
Vue.http.interceptors.push(function (request, next) {
// modify request
resquest.method = 'POST';
// continue to next interceptor
next();
});
Vue.http.interceptors.push(function (request, next) {
// modify request
resquest.method = 'POST';
// continue to next interceptor
next(function (response) {
// modify response
response.data = '...';
});
});
Vue.http.interceptors.push(function (request, next) {
// modify request ...
// stop and return response
next({
data: '...',
status: 404,
statusText: 'Not found'
});
});
Good job.
Maybe documentation needs to be updated.
Thanks! I update the docs when this feature is released with v0.8.0
I've just updated to the develop branch and I've tried to use the new syntax and I'm getting the error 'next is not a function'.
Is there something I'm missing?
The develop has no updated dist build, you need to npm install the dev dependencies and run npm run build to get the updated dists.
Of course! For some reason, installing via github didn't include the build folder, however manually downloading and adding this folder allowed me to build and use the updated package.
Thanks for your help!
@kubacode Just get v0.8.0 which has the latest dist build.
Most helpful comment
Refactored interceptors which now supports returning a response instead of moving on with the next interceptor.
Request processing
Request and Response processing
Return a Response and stop processing