I have this method inside service code.
list.service.ts
public getList(id: string): Observable<ListData> {
const url = this.config.getUrl + '/${id}'
return this.http.get<ListData>(url);
}
and I'm trying to catch response code from this method and have user-friendly message on any error inside the component.
app.component.ts
public ngOnInit() {
this.isWaiting = true;
const id = 'testid'
this.service.getList(id).pipe(
finalize(() => this.isWaiting = false)
).subscribe(
listData => //do something with success result,
error => { -------------------- error.status does not contain response code.
if (error.status === '403')
{ console.log("You're not authorized") }
else if (error.status === '500')
{ console.log("Something wrong!!") }
....
etc...
}
);
}
But error.status is not returning anything here. Is there a proper way to catch http status code in this case?