Currently, I am working with Angular2 and Ionic2 using typescript and have a requirement to manage responses from the backend service.
- The response may either be empty with http status 200
- or it could be a json object containing an error message property that needs to be shown to the user.
This is how I'm sending my request:
this.http.put(***).subscribe((data) => {
The challenge I'm facing is that when the data parameter is provided, rxjs attempts to serialize it from JSON, causing an error if it's empty. On the other hand, if I don't provide the data parameter, I can handle the empty response but then how do I access the error message property if it exists?
I prefer not to make any changes on the backend side to ensure proper http error codes in case of an error. Is there a solution to deal with this situation?