26 lines
604 B
Rust
26 lines
604 B
Rust
use axum::{
|
|
http::StatusCode,
|
|
response::{IntoResponse, Response},
|
|
};
|
|
|
|
pub enum MyError {
|
|
MySQLError(mysql::Error),
|
|
}
|
|
|
|
impl IntoResponse for MyError {
|
|
fn into_response(self) -> Response {
|
|
let (status, message) = match self {
|
|
// # TODO: Don't expose error messages once this goes into production
|
|
MyError::MySQLError(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
|
|
};
|
|
|
|
(status, message).into_response()
|
|
}
|
|
}
|
|
|
|
impl From<mysql::Error> for MyError {
|
|
fn from(error: mysql::Error) -> Self {
|
|
Self::MySQLError(error)
|
|
}
|
|
}
|