Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
replace vestigial unwraps with proper error reporting (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello authored Feb 12, 2024
1 parent 3bcbb23 commit e3047a6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions capture/src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit e3047a6

Please sign in to comment.