fix: error handling
This commit is contained in:
parent
2e7c80d26c
commit
5392199fbb
@ -3,7 +3,7 @@ use axum::{
|
|||||||
async_trait, body::BoxBody, extract::FromRequest, http::Request, response::IntoResponse,
|
async_trait, body::BoxBody, extract::FromRequest, http::Request, response::IntoResponse,
|
||||||
};
|
};
|
||||||
use ssh_key::{Certificate, SshSig};
|
use ssh_key::{Certificate, SshSig};
|
||||||
|
use tracing::trace;
|
||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -20,12 +20,11 @@ where
|
|||||||
async fn from_request(req: Request<BoxBody>, state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request<BoxBody>, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let body = String::from_request(req, state)
|
let body = String::from_request(req, state)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| err.into_response())
|
.context("failed to extract body")?;
|
||||||
.unwrap(); //.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))?;
|
||||||
|
trace!(%body, "extracted certificate");
|
||||||
Ok(Self(cert))
|
Ok(Self(cert))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,11 +42,10 @@ where
|
|||||||
async fn from_request(req: Request<BoxBody>, state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request<BoxBody>, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let body = String::from_request(req, state)
|
let body = String::from_request(req, state)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| err.into_response())
|
.context("failed to extract body")?;
|
||||||
.unwrap(); //.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))?;
|
||||||
|
trace!(%body, "extracted signature");
|
||||||
Ok(Self(sig))
|
Ok(Self(sig))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user