Last active
February 24, 2025 00:12
-
-
Save lil5/484466cbbb075eba4bd6c7bb87560a54 to your computer and use it in GitHub Desktop.
Http Err for easy error handling in axum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // License WTFPL | |
| pub mod http_err { | |
| use axum::http::StatusCode; | |
| pub type HttpResult<T> = Result<T, HttpErr>; | |
| pub type HttpErr = (StatusCode, String); | |
| pub fn internal_error<E>(err: E) -> HttpErr | |
| where | |
| E: std::error::Error, | |
| { | |
| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()) | |
| } | |
| pub fn bad_error<E>(err: E) -> HttpErr | |
| where | |
| E: std::error::Error, | |
| { | |
| (StatusCode::BAD_REQUEST, err.to_string()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment