throwError method signature taking an error value is being removed in version 8. I’m currently on rxjs version 7.5.7. Angular 15.
Also be sure you import your custom NotFoundError class, rather than from rxjs (same thing in the component), which auto import will do.
Below is the implementation I used:
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { AppError } from '../common/app-error';
import { NotFoundError } from '../common/not-found-error';
deletePost(id: string, urlOverride?: string) {
let tempUrl = urlOverride ?? this.url;
return this.http.delete(tempUrl + '/' + id).pipe(
catchError((error: Response) => {
if (error.status === 404) {
throwError(() => new NotFoundError())
}
let proveObservable = throwError(() => new AppError(error));
return proveObservable;
})
);
}
Incorporating the private ‘handleError’ method looks the same that @westley accomplished it.
deletePost(id: string, urlOverride?: string) {
let tempUrl = urlOverride ?? this.url;
return this.http.delete(tempUrl + '/' + id).pipe(
catchError(this.handleError)
);
}
private handleError(error: Response) {
if (error.status === 400)
return throwError(() => new BadInput);
else if (error.status === 404)
return throwError(() => new NotFoundError());
else
return throwError(() => new AppError(error));
}