error codes for errors
All checks were successful
CI / checks (push) Successful in 58s

This commit is contained in:
Robin Appelman 2025-10-21 13:26:58 +02:00
commit b3f0f8ff54

View file

@ -46,11 +46,18 @@ pub enum SetupError {
Other(String),
}
impl Error {
pub fn status_code(&self) -> StatusCode {
match self {
Error::NotFound => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
impl IntoResponse for Error {
fn into_response(self) -> Response {
match self {
Error::NotFound => (StatusCode::NOT_FOUND, "not found").into_response(),
e => format!("{:#}", e).into_response(),
}
let status_code = self.status_code();
(status_code, format!("{:#}", self)).into_response()
}
}