]> git.proxmox.com Git - cargo.git/commit
Always nicely show errors from crates.io if possible
authorSean Griffin <sean@seantheprogrammer.com>
Thu, 21 Mar 2019 18:10:43 +0000 (12:10 -0600)
committerSean Griffin <sean@seantheprogrammer.com>
Thu, 21 Mar 2019 18:10:43 +0000 (12:10 -0600)
commit9759340078b98f6e49f28f1a09827196d87d1e85
tree64f900f12af5c79a063712a00febe00d7fa0a5cc
parentbd60ac8b0a3a68d478ec61d4bf64baeca61a43c8
Always nicely show errors from crates.io if possible

Currently if Cargo ever gets a non-200 response, it will either not show
the error at all (if it was a 403 or 404), or spit out the entire
response body. Historically crates.io has served a 200 for most errors
to work around this, but we've stopped doing this as it causes problems
for other clients.

Additionally, we're starting to server more errors that have semantic
meaning (429 for rate limiting, 503 when we're in read only mode). If
the request specifies "Accept: application/json", we should ideally
return the errors formatted nicely. This isn't always true, but it's
what we'd like to do going forward.

While the output that Cargo puts out at least contains the actual
message, it's buried under a ton of useless info. This changes the
behavior so that if the response was valid JSON in the format that Cargo
expects, it just shows that (along with a description of the response
status), and only falls back to spitting out everything if it can't
parse the response body.

I'd love to add some more tests for this, but I've had trouble finding
anywhere in the test suite that exercises these paths.
src/crates-io/Cargo.toml
src/crates-io/lib.rs