added: more error variants

This commit is contained in:
shimun 2023-03-10 10:45:07 +01:00
parent e696663aec
commit 2688c81aed
Signed by: shimun
GPG Key ID: E0420647856EA39E
2 changed files with 7 additions and 2 deletions

View File

@ -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,

View File

@ -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))
} }