All my Backend API requests return new token information in headers, even when them throw exceptions. In the next request I need to send these new token information.
So I'm trying to figure out an unique and standard way to do that:
let requestOptions = new RequestOptions(Object.assign({
method: method,
url: environment.apiHost + url,
body: body,
headers: authenticatedRequest ? this.requestService.getAuthHeaders() : this.requestService.getJsonHeaders(),
withCredentials: authenticatedRequest
}));
this.http.request(new Request(requestOptions))
.map((res:Response) => this.storageService.setAuthInfo(res.headers))
.catch((error:any) => this.storageService.setAuthInfo(res.headers));
For now I have to set new token in map and catch methods. Is there a method which is called both on success and error cases where I could set new token info (this.storageService.setAuthInfo(res.headers)
) ?