1use std::{error::Error as StdError, fmt};
2
3use http::StatusCode;
4
5use crate::response::IntoResponse;
6
7pub type BoxError = Box<dyn StdError + Send + Sync>;
8
9#[derive(Debug)]
10pub struct Error {
11 inner: BoxError,
12}
13
14impl Error {
15 pub fn new(error: impl Into<BoxError>) -> Self {
16 Self {
17 inner: error.into(),
18 }
19 }
20
21 pub fn into_inner(self) -> BoxError {
22 self.inner
23 }
24}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 self.inner.fmt(f)
29 }
30}
31
32impl StdError for Error {
33 fn source(&self) -> Option<&(dyn StdError + 'static)> {
34 Some(&*self.inner)
35 }
36}
37
38impl IntoResponse for Error {
39 fn into_response(self) -> crate::response::Response {
40 (StatusCode::INTERNAL_SERVER_ERROR, self.inner.to_string()).into_response()
41 }
42}