I am posting a request and I am suppose to receive a 'success' string back as response. I am getting an HttpResponseError with the following information posted in the image below.
PurchaseOrderService
postPurchaseOrderCustom(purchaseOrderCustom: PurchaseOrderSaveCustom) {
const url = `${this.localUrl}purchaseOrderCustom`;
return this.http.post<String>(url, purchaseOrderCustom, {headers: this.header})
.pipe(
catchError(this.handleError('postPurchaseOrderCustom', 'I am an error'))
);
}
PurchaseOrderComponent
this.purchaseOrderService.postPurchaseOrderCustom(purchaseOrderCustom).subscribe( response => {
console.log("Testing", response);
},
error => {
console.error('errorMsg',error );
}
The way I am doing it is the same way its done in the documentation. Do point out to me what I am doing wrong.
I was also facing same issue while getting pdf data buffer in response and I handled it in following manner, it's working for me
server side
in Angular Service downloadPdf(dateRange, labs){
} And in Component.ts file
Like it has already been said, this has everything to do with the response coming from your server.
In my case, I had a Spring Boot application that returned this:
and this was the response I was getting on the Angular end:
So what I did was create a custom
CustomHttpResponse
class in my Spring Boot application and then changed the code in my controller to this:Now I'm getting this:
Essentially, this error occurs when Angular is expecting JSON but gets something else instead
This related to your api respond type ,
success
is not valid json format,by defaultHttpClient
is expected json response type and try to parse it later . You can solve this by set the respond type to text like this