Search code examples
web-servicesresthttp-status

What http status code should I use when customer configuration is not correct?


I am unsure what http status code to return when a customer calls my API, but the requested action cannot be completed for reasons that the customer can fix.

In this case, the http request itself may be fine, but it will not succeed until the customer logs into the front end and updates their configuration. (I will return a body with some informative message to indicate this.)

Is 412 - Precondition Failed - appropriate for this case?


Solution

  • 412 Precondition Failed

    The server does not meet one of the preconditions that the requester put on the request.

    This statuscode has a spefic meaning. It is about a condition that the client stated in the request, whichthe server was unable to fullfill. Don't use this status code for your scenario.

    The only HTTP status code that can be used is 400 Bad Request. It is the catch-all status code for all errors that the client can fix. Since you return detailed information about how the client can do this, the client has everything necessary.

    see Wikipedia: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes