How to transform a HttpResponse into a HttpErrorResponse

William Ghelfi

I have a web service returning custom errors inside a 200 Response, in a classic errors object.

This breaks my workflow and patterns, where I usually intercept proper HTTP error status codes and go on with handling the various error cases from there.

I need to transform these custom errors into proper HttpErrorResponse errors via an interceptor, so that I can then intercept those now-proper errors and continue with my application per usual best practices.

Things I can't do:

  • Have the web service modified so that it returns proper HTTP errors
  • Have another web service in the middle to handle the transformation before the Response hits the client application

What I'd like to do:

So that when in the near future I'll be working on several other applications that use the same unmodifiable web service, I can just drop the CustomErrorInterceptor in and call it a day.

William Ghelfi

And here's the answer a buddy of mine just found:

throw new HttpErrorResponse({ error: 'bar', status: 403 });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related