Search code examples
resthttp-error

Which HTTP code to use for a system error?


I am building a RESTful API to control some hardware. Part of the API is getting information from a serial (RS-232) interface. Some of the time, this can fail for whatever reason (disconnect, device broken, etc).

What HTTP error code should I use? I was thinking in the 5xx range, as the request is correct, but I cannot find a suitable one.


Solution

  • 500 seems like the most generic or suitable. from wikipedia:

    5xx Server error The server failed to fulfil an apparently valid request.

    and

    500 Internal Server Error A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

    The clients shouldn't care why did the server have errors processing the request (system error), they should only care that the request has failed, and it's the server fault.