Click here to Skip to main content
15,885,091 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When calling the service success response is getting correctly but error response shows empty in the UI. In the network tab status code is 200 and also in response shows a correct error message but in the console, the tab shows the below error:
https://i.stack.imgur.com/BtI0E.png[^]
restoration(Id: string): Observable<ServerResponse> {
 return this.http.put<ServerResponse>(`${url.restoration}?id=${Id}`, {
      headers: this.jsonHeaders
});
}


What I have tried:

restoration(Id: string): Observable<ServerResponse> {
 return this.http.put<ServerResponse>(`${url.restoration}?id=${Id}`, {
      headers: {accept: 'text/plain'}
});
}
Posted
Updated 2-Sep-20 21:20pm
v2
Comments
Richard Deeming 3-Sep-20 5:29am    
A status code of 200 means the request succeeded. An error response should have a different status code.
List of HTTP status codes - Wikipedia[^]

1 solution

Based on the image, your error response is in XML format and seems it is expected and being parsed as a JSON. Given the mismtach, you get an error while parsing.

Next followup query could be to fix it:
1. Client side, don't blindly assume it as json, take it as text and work out
2. Server side, if it's in your control, return json response instead of a XML. Then on client side you can parse as returned:
JavaScript
header: {'Content-Type: application/json'};

Based on image, you seem to knw how to use browsers web developer tool. Use it and see what is the response there and plan your next steps.
 
Share this answer
 
v2
Comments
dvarun 3-Sep-20 3:29am    
i have done this method can you please tell me in another way
Sandeep Mewara 3-Sep-20 3:47am    
There's nothing more to add. Don't parse the response as json if that is not the case. Clearly, you get an xml - treat like one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900