I've made an http interceptor in which I'm filtering HttpEvent
to get only HttpResponse
. It looks like that:
return next.handle(requestToSend).pipe(
filter(event => event instanceof HttpResponse),
map((event: HttpResponse<any>) => this.handleResponse(event)),
catchError(error => this.handleErrors(error))
);
And here is my question: Is it a good idea to filter responses to get only HttpResponse
? Won't it break anything, like e.g. Web Sockets? Does it actually work like some kind of firewall?
Your interceptor only handles requests made by the HttpClient
. So it should not break anything related to other HTTP request like websockets, as long as you don't use the HttpClient
to perform those requests.
Regarding the filtering of the requests, it makes sense, because there are different kind of events that can be returned by the handle
method. But in the following map()
function the event is strictly typed as HttpResponse
.