I have an interceptor that adds a token in the headers. However, if I use it after a POST request my Observer in the subscription is not triggered.
Interceptor:
My workaround is an HttpInterceptor that catches errors when the status code is 200 and returns an HttpResponse with a null body instead (just like HttpClient does with 204 Not Content responses):
@Injectable()
export class EmptyResponseBodyErrorInterceptor implements HttpInterceptor {
intercept(req: HttpRequest, next: HttpHandler): Observable> {
return next.handle(req)
.catch((err: HttpErrorResponse) => {
if (err.status == 200) {
const res = new HttpResponse({
body: null,
headers: err.headers,
status: err.status,
statusText: err.statusText,
url: err.url
});
return Observable.of(res);
} else {
return Observable.throw(err);
}
});
}
}