Hi, I’m using http-fetch-client to request a resource on webapi.
I have put a few interceptors on my httpclient like this:
config.withBaseUrl(app.HttpSettings.BaseUrl)
.withInterceptor({
request(request: Request) {
self.logger.info(`Requesting ${request.method} ${request.url}`);
return request;
},
response(response: Response) {
self.logger.info(`Response ${response.status} ${response.url}`);
if (response instanceof TypeError) {
throw Error(response['message']);
}
if (response.status == 401 && response.url.indexOf(self.httpClient.baseUrl) == 0) {
eventAggregator.publish(Events.Unauthorized, null);
return Promise.reject(response);
}
else if (response.status >= 400) {
return response.text()
.then(resp => {
let json: any = {};
let error = 'Network Error!!';
try {
json = JSON.parse(resp);
}
catch (e) { }
if (json.message)
error = json.message;
else if (json.error)
error = json.error;
else if (response.statusText)
error = response.statusText;
if (error)
throw new Error(error);
return Promise.reject(resp);
});
}
return response;
},
requestError(error: Error) {
if (error !== null)
throw Error(error.message);
return error;
},
responseError(error: Error) {
if (error !== null)
throw Error(error.message);
return error;
}
});
});
When my webapi return a 401 Unauthorized, my responseError is not called.
Why?
Thanks