From 6757723b779ad0f0b9e239f3ff9757d40b4f91d4 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 18 May 2024 20:26:26 +0100 Subject: [PATCH] feat(server/webhook): log errors in webhook requests --- crates/server/src/actors/webhook/server.rs | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/server/src/actors/webhook/server.rs b/crates/server/src/actors/webhook/server.rs index d3b53c7f..78dad898 100644 --- a/crates/server/src/actors/webhook/server.rs +++ b/crates/server/src/actors/webhook/server.rs @@ -2,7 +2,7 @@ use std::net::SocketAddr; use actix::prelude::*; -use tracing::{debug, info}; +use tracing::{info, warn}; use crate::actors::webhook::message::WebhookMessage; @@ -25,17 +25,24 @@ pub async fn start( // query: String, headers: warp::http::HeaderMap, body: bytes::Bytes| async move { + info!("POST received"); let bytes = body.to_vec(); let request_data = String::from_utf8_lossy(&bytes).to_string(); let id = ulid::Ulid::new().to_string(); match headers.get("Authorization") { Some(auhorisation) => { - debug!(id, path, "Received webhook"); + info!(id, path, "Received webhook"); let authorisation = auhorisation .to_str() - .map_err(|_| warp::reject())? // valid characters + .map_err(|e| { + warn!("Invalid value in authorization: {:?}", e); + warp::reject() + })? // valid characters .strip_prefix("Basic ") - .ok_or_else(warp::reject)? // must start with "Basic " + .ok_or_else(|| { + warn!("Authorization must be 'Basic'"); + warp::reject() + })? // must start with "Basic " .to_string(); let message = WebhookMessage::new( id, @@ -45,10 +52,19 @@ pub async fn start( ); recipient .try_send(message) - .map(|_| warp::reply::with_status("OK", warp::http::StatusCode::OK)) - .map_err(|_| warp::reject()) + .map(|_| { + info!("Message sent ok"); + warp::reply::with_status("OK", warp::http::StatusCode::OK) + }) + .map_err(|e| { + warn!("Unknown error: {:?}", e); + warp::reject() + }) + } + _ => { + warn!("No Authorization header"); + Err(warp::reject()) } - _ => Err(warp::reject()), } }, );