Closed Vespand closed 10 months ago
Not sure I should go with with this PR, the true
boolean I had set was only meant to work for a specific error to reset. (That error being the response status being 401) Otherwise you are able to set your own resetOnResponseError
function.
This is not about resetOnResponseError
setting at all
Any «rejected» interceptor should throw error for next «rejected» interceptor, otherwise error will be silent and any request will be success (no error handling)
There is logic @refactorjs/ofetch
for interceptors - https://github.com/refactorjs/ofetch/blob/main/src/ofetch.ts#L239
If function will not return anything - call Promise.reject(error)
, why current interceptor is different and break this logic in chain?
This PR will add same logic, throwing error
I can rewrite this code, for using onResponseError
, which is actually better and cleaner, but onResponseError need to return number, such as
this.responseInterceptor = this.http.onResponseError(error => {
if (typeof this.auth.options.resetOnResponseError === 'function') {
this.auth.options.resetOnResponseError(error, this.auth, this.scheme)
}
else if (this.auth.options.resetOnResponseError && error?.response?.status === 401) {
this.scheme.reset?.()
throw new ExpiredAuthSessionError();
}
});
But need fix for @refactorjs/ofetch, for returning number for responseInterceptor
and similar hooks
onResponseError(fn: (error: any) => any): number {
return this.interceptors.response.use(undefined, (error: any) => fn(error) || Promise.reject(error))
}
I hope it's cleaner answer what happening and where is problem :)
I understand what you're saying now, I'll put this in v3.1.1 so for now ill close this.
Method onResponseError doesn't work (also all
$http.interceptors.response
with errors handlers)This PR fix problem
How to reproduce:
playground/pages/index.vue
with above ($http.get should return 404 error code)