Skip to content

Commit

Permalink
Auto merge of #10860 - Eh2406:4xxDocs, r=ehuss
Browse files Browse the repository at this point in the history
servers should use 404

Clarify the docs in lieu of our conversation at https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Sparse.20Registry.20Errors
  • Loading branch information
bors committed Jul 13, 2022
2 parents 44684e0 + c032c25 commit 289ab53
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/doc/src/reference/registries.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ 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 use the 200 response code for success.
Errors should use an appropriate response code, such as 404.
Failure
responses should have a JSON object with the following structure:

```javascript
{
Expand All @@ -336,10 +337,10 @@ 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.

For backwards compatibility, servers should ignore any unexpected query
parameters or JSON fields. If a JSON field is missing, it should be assumed to
Expand Down

0 comments on commit 289ab53

Please sign in to comment.