From e3047a6ff7cbca2e0dc745e412ae6a178c62e1eb Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Mon, 12 Feb 2024 18:58:39 +0100 Subject: [PATCH] replace vestigial unwraps with proper error reporting (#14) --- capture/src/capture.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/capture/src/capture.rs b/capture/src/capture.rs index d7303fd..7f90d57 100644 --- a/capture/src/capture.rs +++ b/capture/src/capture.rs @@ -75,10 +75,16 @@ pub async fn event( "application/x-www-form-urlencoded" => { tracing::Span::current().record("content_type", "application/x-www-form-urlencoded"); - let input: EventFormData = serde_urlencoded::from_bytes(body.deref()).unwrap(); + let input: EventFormData = serde_urlencoded::from_bytes(body.deref()).map_err(|e| { + tracing::error!("failed to decode body: {}", e); + CaptureError::RequestDecodingError(String::from("invalid form data")) + })?; let payload = base64::engine::general_purpose::STANDARD .decode(input.data) - .unwrap(); + .map_err(|e| { + tracing::error!("failed to decode form data: {}", e); + CaptureError::RequestDecodingError(String::from("missing data field")) + })?; RawEvent::from_bytes(payload.into()) } ct => {