Encountering issues with 422 error handling in my HTTP request. The error block is not executing as expected when using the catchError operator in the service. If no errors occur, the code functions properly. However, I need to show an error message on the page instead of just logging it to the console.
The following is the HTTP error response:
Only receiving the error message in the console:
https://i.sstatic.net/m1Qtt.png
My goal is to display the error message on the page. Below is my HTTP request:
renderPlugin(id): Observable<any> {
return this.http
.get(`${environment.kbUrl}/${id}?_as_json=1&_nbp=1`, {
responseType: "text",
observe: "response"
})
.pipe(
catchError((res: HttpErrorResponse) => {
console.log(JSON.stringify(res));
this.toastr.error("error", JSON.stringify(res));
return throwError(JSON.stringify(res));
})
);
}
Here is how I'm subscribing to it:
this.pluginsService.renderPlugin(this.currentId).subscribe(res =>{
this.currentString = res.body;
this.plugin = this.currentString.data.content;
console.log(this.plugin);
},
err =>{
this.plugin = err;
});