How to Return Status Code 500 or 400 from SOE

5300
1
03-24-2016 04:03 AM
Haider_AliFaheem
New Contributor II

i have implemented the Rest SOE and everything working fine except returning the error.when i raising the exception still response status code is 200 OK and in body i found the exception code and Message. i want that my client catch that exception rather then reading the response and then figure out it is exception or normal response.

i also try to do the same as describe here but still status is 200 Ok and X-HTTP-Status is shown in header

SOE REST Service - Is it possible to send the http status code from the operation

Thanks

Haider

0 Kudos
1 Reply
nicogis
MVP Frequent Contributor

If you use JavaScript client, JSONP callbacks to work you need always send a status of 200.

So REST API sends a status code of 200 even when your request failed.

You can add the HTTP status in a error JSON object or you can set a custom HTTP header using responseProperties.

For instance:

responseProperties = "{

  •   \"Content-Type\" : \"application/pdf\",
  •   \"X-HTTP-Status\" : \"500 - An error occurred while generating the pdf file.\"
  • }";
0 Kudos