calories/server/src/my_structs/myerror.rs
Knyffen b92483998b Enable running webassembly in the browser
Create two workspaces, one for the server code, and one for browser
code/wasm
2024-08-16 13:05:57 +02:00

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)
}
}