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
10/// A simple wrapper around an error that implements [`IntoResponse`].
11#[derive(Debug, thiserror::Error)]
12#[error(transparent)]
13pub struct ErrorWrapper<T>(#[from] pub T);
14
15impl<T> IntoResponse for ErrorWrapper<T>
16where
17    T: std::error::Error,
18{
19    fn into_response(self) -> Response {
20        // TODO: make this a bit more user friendly
21        (StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response()
22    }
23}