Make the error wrapper log errors

This commit is contained in:
Quentin Gliech
2025-04-17 16:51:37 +02:00
parent 8ba47e9b37
commit 93590a0375
2 changed files with 21 additions and 10 deletions

View File

@@ -7,6 +7,8 @@
use axum::response::{IntoResponse, Response};
use http::StatusCode;
use crate::record_error;
/// A simple wrapper around an error that implements [`IntoResponse`].
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
@@ -14,10 +16,16 @@ pub struct ErrorWrapper<T>(#[from] pub T);
impl<T> IntoResponse for ErrorWrapper<T>
where
T: std::error::Error,
T: std::error::Error + 'static,
{
fn into_response(self) -> Response {
// TODO: make this a bit more user friendly
(StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response()
let sentry_event_id = record_error!(self.0);
(
StatusCode::INTERNAL_SERVER_ERROR,
sentry_event_id,
self.0.to_string(),
)
.into_response()
}
}

View File

@@ -46,17 +46,20 @@ macro_rules! record_error {
Option::<$crate::sentry::SentryEventID>::None
}};
($error:expr) => {{
tracing::error!(message = &$error as &dyn std::error::Error);
// With the `sentry-tracing` integration, Sentry should have
// captured an error, so let's extract the last event ID from the
// current hub
$crate::sentry::SentryEventID::for_last_event()
}};
($error:expr, $pattern:pat) => {
if let $pattern = $error {
tracing::error!(message = &$error as &dyn std::error::Error);
// With the `sentry-tracing` integration, Sentry should have
// captured an error, so let's extract the last event ID from the
// current hub
$crate::sentry::SentryEventID::for_last_event()
record_error!($error)
} else {
tracing::warn!(message = &$error as &dyn std::error::Error);
None
record_error!($error, !)
}
};
}