Why the spoiler does not give ErrorResponse to the handler?

I'm trying to write an interceptor which will prevent script termination in case of an error from the server.
So I call the service method in the component:
const res = await this.service.getLandingPage(url);
// do actions with res

The method of service:
getLandingPage async<T>(url: string): Promise<Page> {
 return this.get<Page>(url,
 observe: "response"

return next.handle(request).pipe(
 catchError((error: HttpErrorResponse) => {
 return EMPTY;

In this case, if the response from the server successful in the res comes HttpResponse as expected, but if the server responded with error in res nothing (undefined). If the spoiler is empty Observable to return an error, the script will fall and in the component string to the console.log(res) scenario will not happen. How to make a spoiler so that in the given case, when error from the server at the res got HttpErrorResponse and not undefined?
March 23rd 20 at 19:13
1 answer
March 23rd 20 at 19:15
return throwError(error)

catchError require to return observable, and you slip him plain value
If you do throwError drops the error and to console.log(res) scenario does not reach - daniella6 commented on March 23rd 20 at 19:18
@daniella6, of course decreases, the error in observable flows into the rejected in promise.
If you want to return from promis, not an error object, well make a return of(error)

But it is bad practice, better to await in a try catch to wrap and catch there.
And do not make promises of doing the subscription. - Madalyn.Lueilwitz commented on March 23rd 20 at 19:21
@Madalyn.Lueilwitz, it is clear, usually well done)
I'm doing the bike for the test, and I was wondering if I can in the spoiler to do what is described in the question - daniella6 commented on March 23rd 20 at 19:24
@daniella6, consider catchError it as switchMap, but only for errors. - Madalyn.Lueilwitz commented on March 23rd 20 at 19:27

Find more questions by tags Angular