I use interceptor like this
export class ServerErrorInterceptor implements HttpInterceptor {
constructor(
private appMessageService: AppMessageService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
catchError((error: HttpErrorResponse) => {
this.appMessageService.handleError(error, 'Server request error');
return of();
})
);
}
}
And use HttpClient with firstValueFrom
async create(request: any): Promise<void> {
const response = this.http.post(this.url, request);
await firstValueFrom(response);
}
I expect that of() returns an empty result, so awaiting "create" method should not throw an error. But after "catchError" show an error message, another error throws "sequence contains no elements". How to build a handler pipe to not throw a second error?