DEV Community

Discussion on: Intercepting Http Requests-- Using And Testing Angular's HttpClient

Collapse
 
rossler123 profile image
Markus Rossler

I would like to change a successful HttpResponse to an simulated error, returning an HttpErrorResponse. Any hint? I already tried mapping the event to an error. No success...

Collapse
 
alisaduncan profile image
Alisa

Are you trying to simulate an error response in the service or in the interceptor (for intercepting responses)?

Collapse
 
rossler123 profile image
Markus Rossler

Our server api has some special behaviour, in some cases it replies with an http error instead of a http 200 response with a proper body. This is legacy code, but on purpose. Not to break anything we need to handle with that. Since these are rare cases i want to simulate that and reuse it for unit tests as well.

Thread Thread
 
alisaduncan profile image
Alisa

In a unit test you can simulate errors. Does something like this work for you?
github.com/alisaduncan/tutorial-an...