Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the suitable HTTP status code when request is successful but has warning messages?

Tags:

In proper usage of REST, what is suitable the HTTP status code when request is successful but has warning messages?

In our case; clients are web applications running on browsers. We prefer status codes as following:

  • HTTP 200, 201, 204 when request processed successfully
  • HTTP 422 when request violates some business rules
  • HTTP 500 when unexpected exceptions are occured while processing request

But we couldn't determine which status code should be used when request processed successfully but some information or warning messages need to send to client?

like image 413
ykaragol Avatar asked Feb 29 '16 07:02

ykaragol


2 Answers

In the HTTP protocol there actually is a "warning" header (see Header Field Definitions ). These are HTTP warnings, but you could use code 199 to send what you need:

199 Miscellaneous warning The warning text MAY include arbitrary information to be presented to a human user, or logged.

The problem here is the next bit of specification:

A system receiving this warning MUST NOT take any automated action, besides presenting the warning to the user.

Because of this, I think you're better off adding data about the warning in the response content (and keep using the 200 status code).

like image 86
ChatterOne Avatar answered Oct 16 '22 02:10

ChatterOne


HTTP status codes are determine whether the request has been proceed properly or not and there is no warning status. If you want to provide information about result of your internal functions you should add information status to the response content eg:

{
    status: "WARNING",
    code: "WARNING-CODE"
}
like image 40
Blady214 Avatar answered Oct 16 '22 02:10

Blady214