servers should use 404

This commit is contained in:
Jacob Finkelman 2022-07-13 20:47:50 +00:00
parent 92ff479275
commit ad2b7b1812

View file

@ -320,9 +320,8 @@ visit the registry's website to obtain a token, and Cargo can store the token
using the [`cargo login`] command, or by passing the token on the
command-line.
Responses use a 200 response code for both success and errors. Cargo looks at
the JSON response to determine if there was success or failure. Failure
responses have a JSON object with the following structure:
Responses should use the 200 or 404 response code as appropriate. Failure
responses should have a JSON object with the following structure:
```javascript
{
@ -336,10 +335,11 @@ responses have a JSON object with the following structure:
}
```
Servers may also respond with a 404 response code to indicate the requested
resource is not found (for example, an unknown crate name). However, using a
200 response with an `errors` object allows a registry to provide a more
detailed error message if desired.
If the response has this structure Cargo will display the detailed message to the user, even if the response code is 200.
If the response code indicates an error and the content does not have this structure, Cargo will display to the user a
message intended to help debugging the server error. A server returning an `errors` object allows a registry to provide a more
detailed or user centric error message. The first release of Cargo to support registries Cargo 1.34 (released 2019-04-11) will only
show a human readable error if the code is 200, this has been fixed in all versions since Cargo 1.35 (released 2019-05-23).
For backwards compatibility, servers should ignore any unexpected query
parameters or JSON fields. If a JSON field is missing, it should be assumed to