문제

Of the http codes, what does Chrome interpret as an error?

I have an API that purposefully sends 404's upon a search that doesn't return anything. This shows up as an error in the chrome console, even though everything is operating perfectly fine.

The 500s, and 400s probably show up as error messages. Which ones don't? Which ones show up as warnings?

도움이 되었습니까?

해결책

HTTP status codes are classified into five categories

  • 1xx - Informational
  • 2xx - Successful
  • 3xx - Redirection
  • 4xx - Client Error
  • 5xx - Server Error

See RFC 2616 http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10

Chrome interprets status codes accordingly to this classification. Note that there is no status code that can be interpreted as a warning.

Your usage of 404 is not correct. See 404 definition:

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.

Which is not true for your use-case. You should use 200 OK or 201 Created and return an empty collection as response body. BTW. this also simplifies client's code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top