Skip to content

Instantly share code, notes, and snippets.

@lil5
Last active February 24, 2025 00:12
Show Gist options
  • Select an option

  • Save lil5/484466cbbb075eba4bd6c7bb87560a54 to your computer and use it in GitHub Desktop.

Select an option

Save lil5/484466cbbb075eba4bd6c7bb87560a54 to your computer and use it in GitHub Desktop.
Http Err for easy error handling in axum
// 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