0

Does anyone know what is the best format to return an HTTP response error to the client when facing an exception? A format to handle the error in a dynamic way and the easiest way to catch the exception between server and client

i suggested the following, but i need to get the best format for the error response:

   {
    "FLAG": "ERROR",
    "TEXTEN": "SERVER ERROR – BAD REQUEST"
    }
Sunny
  • 14,522
  • 15
  • 84
  • 129
User7291
  • 1,095
  • 3
  • 29
  • 71
  • What caused the error? Is it a programming error? Is some subsystem not reachable? Did the client do a wrong request? –  Feb 28 '14 at 09:33
  • @LutzHorn I need to handle all kinds of errors, programming,http exception,database erros,flow errors etc.. – User7291 Feb 28 '14 at 09:40

1 Answers1

1

One good solution would be to send back the error code in the answer's headers, using the standardized HTTP codes from the HTTP protocol.

You can also add you own error code and a corresponding human readable message in the JSON body to provide more informations on the encountered error.

For example, for a Bad Request error, the corresponding HTTP code is 400. So you should send back the HTTP code 400 in the response header and the corresponding HTTP message (Bad Request). But some programming languages does not offer out of the box features to read the message. To be sure that the user can read it properly, you can also put it in the JSON body if you want.

Mickäel A.
  • 9,012
  • 5
  • 54
  • 71