Skip to content

Commit 860497d

Browse files
authored
Merge pull request #196 from aochagavia/improve-error-message
Improve error message
2 parents c0491d3 + 5cf221f commit 860497d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/client.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,13 +1679,19 @@ fn validate_registry_response(status: reqwest::StatusCode, body: &[u8], url: &st
16791679
status,
16801680
))),
16811681
s if s.is_client_error() => {
1682-
let text = std::str::from_utf8(body)?;
1683-
// According to the OCI spec, we should see an error in the message body.
1684-
let envelope = serde_json::from_str::<OciEnvelope>(text)?;
1685-
Err(OciDistributionError::RegistryError {
1686-
envelope,
1687-
url: url.to_string(),
1688-
})
1682+
match serde_json::from_slice::<OciEnvelope>(body) {
1683+
// According to the OCI spec, we should see an error in the message body.
1684+
Ok(envelope) => Err(OciDistributionError::RegistryError {
1685+
envelope,
1686+
url: url.to_string(),
1687+
}),
1688+
// Fall back to a plain server error if the body isn't a valid `OciEnvelope`
1689+
Err(_) => Err(OciDistributionError::ServerError {
1690+
code: s.as_u16(),
1691+
url: url.to_string(),
1692+
message: String::from_utf8_lossy(body).to_string(),
1693+
}),
1694+
}
16891695
}
16901696
s => {
16911697
let text = std::str::from_utf8(body)?;

0 commit comments

Comments
 (0)