What is the appropriate HTTP status code when the request is successful, but there are warning messages?

With proper use of REST, what is appropriate for the HTTP status code when the request is successful but contains warning messages?

In our case; Clients are web applications that run in browsers. We prefer status codes as follows:

  • HTTP 200, 201, 204 when the request is processed successfully
  • HTTP 422 when a request violates some business rules.
  • HTTP 500 when unexpected exceptions occur during processing

But we could not determine which status code should be used when the request is processed successfully, but some information or warning messages should be sent to the client?

+5
source share
2 answers

The HTTP protocol actually has a warning header (see Header field definitions ). These are HTTP warnings, but you can use code 199 to send what you need:

199 Other warning The warning text MAY include arbitrary information that must be presented to the user or registered.

The problem here is the following specification bit:

The system receiving this warning MUST NOT take any automatic action, in addition to presenting the warning to the user.

Because of this, I think you are better off adding warning data to the content response (and continue to use status code 200).

+3
source

HTTP status codes determine whether the request was completed correctly or not, and there is no warning status. If you want to provide information about the results of your internal functions, you must add the status of the information to the response content, for example:

{ status: "WARNING", code: "WARNING-CODE" } 
+1
source

Source: https://habr.com/ru/post/1244088/


All Articles