From 5392199fbb192d6066e346c1ee16ff1ab2e6fe9a Mon Sep 17 00:00:00 2001 From: shimun Date: Thu, 8 Dec 2022 18:25:05 +0100 Subject: [PATCH] fix: error handling --- src/api/extract.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/api/extract.rs b/src/api/extract.rs index 333bc31..4b9ef79 100644 --- a/src/api/extract.rs +++ b/src/api/extract.rs @@ -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, state: &S) -> Result { 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, state: &S) -> Result { 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)) } }