mas_axum_utils/
error_wrapper.rs

1// Copyright 2024 New Vector Ltd.
2// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7use axum::response::{IntoResponse, Response};
8use http::StatusCode;
9
10use crate::record_error;
11
12/// A simple wrapper around an error that implements [`IntoResponse`].
13#[derive(Debug, thiserror::Error)]
14#[error(transparent)]
15pub struct ErrorWrapper<T>(#[from] pub T);
16
17impl<T> IntoResponse for ErrorWrapper<T>
18where
19    T: std::error::Error + 'static,
20{
21    fn into_response(self) -> Response {
22        // TODO: make this a bit more user friendly
23        let sentry_event_id = record_error!(self.0);
24        (
25            StatusCode::INTERNAL_SERVER_ERROR,
26            sentry_event_id,
27            self.0.to_string(),
28        )
29            .into_response()
30    }
31}