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};
8
9use crate::InternalError;
10
11/// A simple wrapper around an error that implements [`IntoResponse`].
12#[derive(Debug, thiserror::Error)]
13#[error(transparent)]
14pub struct ErrorWrapper<T>(#[from] pub T);
15
16impl<T> IntoResponse for ErrorWrapper<T>
17where
18 T: std::error::Error + 'static,
19{
20 fn into_response(self) -> Response {
21 InternalError::from(self.0).into_response()
22 }
23}