fix: error handling

This commit is contained in:
shimun 2022-12-08 18:25:05 +01:00
parent 2e7c80d26c
commit 5392199fbb
Signed by: shimun
GPG Key ID: E0420647856EA39E

View File

@ -3,7 +3,7 @@ use axum::{
async_trait, body::BoxBody, extract::FromRequest, http::Request, response::IntoResponse,
};
use ssh_key::{Certificate, SshSig};
use tracing::trace;
use super::ApiError;
#[derive(Debug, Clone)]
@ -20,12 +20,11 @@ where
async fn from_request(req: Request<BoxBody>, state: &S) -> Result<Self, Self::Rejection> {
let body = String::from_request(req, state)
.await
.map_err(|err| err.into_response())
.unwrap(); //.context("failed to extract body")?;
.context("failed to extract body")?;
let cert = Certificate::from_openssh(&body)
.with_context(|| format!("failed to parse '{}'", body))?;
trace!(%body, "extracted certificate");
Ok(Self(cert))
}
}
@ -43,11 +42,10 @@ where
async fn from_request(req: Request<BoxBody>, state: &S) -> Result<Self, Self::Rejection> {
let body = String::from_request(req, state)
.await
.map_err(|err| err.into_response())
.unwrap(); //.context("failed to extract body")?;
.context("failed to extract body")?;
let sig = SshSig::from_pem(&body).with_context(|| format!("failed to parse '{}'", body))?;
trace!(%body, "extracted signature");
Ok(Self(sig))
}
}