added: more error variants
This commit is contained in:
parent
e696663aec
commit
2688c81aed
@ -174,12 +174,17 @@ pub enum ApiError {
|
|||||||
AuthenticationRequired(String),
|
AuthenticationRequired(String),
|
||||||
#[error("invalid ssh signature")]
|
#[error("invalid ssh signature")]
|
||||||
InvalidSignature,
|
InvalidSignature,
|
||||||
|
#[error("malformed ssh signature: {0}")]
|
||||||
|
ParseSignature(anyhow::Error),
|
||||||
|
#[error("malformed ssh certificate: {0}")]
|
||||||
|
ParseCertificate(anyhow::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiResult<T> = Result<T, ApiError>;
|
type ApiResult<T> = Result<T, ApiError>;
|
||||||
|
|
||||||
impl IntoResponse for ApiError {
|
impl IntoResponse for ApiError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
trace!({ error = ?self }, "returned error for request");
|
||||||
(
|
(
|
||||||
match self {
|
match self {
|
||||||
Self::CertificateNotFound => StatusCode::NOT_FOUND,
|
Self::CertificateNotFound => StatusCode::NOT_FOUND,
|
||||||
|
@ -21,7 +21,7 @@ where
|
|||||||
.context("failed to extract body")?;
|
.context("failed to extract body")?;
|
||||||
|
|
||||||
let cert = Certificate::from_openssh(&body)
|
let cert = Certificate::from_openssh(&body)
|
||||||
.with_context(|| format!("failed to parse '{}'", body))?;
|
.with_context(|| format!("failed to parse '{}'", body)).map_err(ApiError::ParseCertificate)?;
|
||||||
trace!(%body, "extracted certificate");
|
trace!(%body, "extracted certificate");
|
||||||
Ok(Self(cert))
|
Ok(Self(cert))
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ where
|
|||||||
.await
|
.await
|
||||||
.context("failed to extract body")?;
|
.context("failed to extract body")?;
|
||||||
|
|
||||||
let sig = SshSig::from_pem(&body).with_context(|| format!("failed to parse '{}'", body))?;
|
let sig = SshSig::from_pem(&body).with_context(|| format!("failed to parse '{}'", body)).map_err(ApiError::ParseSignature)?;
|
||||||
trace!(%body, "extracted signature");
|
trace!(%body, "extracted signature");
|
||||||
Ok(Self(sig))
|
Ok(Self(sig))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user