use http::StatusCode;
use topcoat_core::{
context::Cx,
error::{Error, Result},
};
use crate::response::{IntoResponse, Response};
pub fn internal_server_error(error: impl Into<Error>) -> InternalServerError {
InternalServerError::new(error.into())
}
#[derive(Debug)]
pub struct InternalServerError {
_inner: Error,
}
impl InternalServerError {
fn new(inner: Error) -> Self {
Self { _inner: inner }
}
}
impl From<Error> for InternalServerError {
fn from(value: Error) -> Self {
Self::new(value)
}
}
impl std::fmt::Display for InternalServerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("internal server error")
}
}
impl std::error::Error for InternalServerError {}
impl IntoResponse for InternalServerError {
fn into_response(self, cx: &Cx) -> Result<Response> {
(StatusCode::INTERNAL_SERVER_ERROR, "internal server error").into_response(cx)
}
}