[SalesForce] Http response always has error status as bad request

I have a requirment to integrate a .net system with Salesforce using REST API. In that I need to show a proper error message on request payload error.

From .net system I get proper error status like "400 BillingAddress is not complete", tested this in "Advance REST client" in Chrome.
enter image description here

But in Salesforce I get the response like "System.HttpResponse[Status=Bad Request, StatusCode=400]".

I am getting a correct StatusCode but not Status. Used getStatus() method and getBody() method. Can anyone please let me know how to get the Status using REST API.

Best Answer

I resolved this by changing in API end by sending the error message as JSON response. By default Salesforce shows only default message for respective Status Code.

In my case I'm getting a response with status code as 400 and Salesforce set the status message as "Bad Request". So I changed in my API end to send a JSON response with error message, from that I can show a proper error message in Salesforce.

Related Topic