Skip to main content

Module error

Module error 

Source
Expand description

§modo::error

HTTP-aware error type for the modo web framework.

This module provides Error, an opinionated error type that carries an HTTP status code, a human-readable message, an optional structured details payload, an optional source error, and an optional machine-readable error code. Error implements axum::response::IntoResponse, so it can be returned directly from axum handlers.

§Provides

  • Error — primary framework error with status code, message, optional source/details/code
  • Result — type alias for std::result::Result<T, Error>
  • HttpError — lightweight Copy enum of common HTTP error statuses, converts into Error

Automatic From conversions into Error are provided for std::io::Error (→ 500), serde_json::Error (→ 400), and serde_yaml_ng::Error (→ 500).

§Quick start

use modo::error::{Error, Result};

fn find_user(id: u64) -> Result<String> {
    if id == 0 {
        return Err(Error::not_found("user not found"));
    }
    Ok("Alice".to_string())
}

§Error identity

After Error is converted into an HTTP response, the source error is discarded. Use Error::with_code to attach a static code string that survives through the response pipeline and can be read back via Error::error_code.

use modo::error::Error;

let err = Error::unauthorized("unauthorized")
    .with_code("jwt:expired");
assert_eq!(err.error_code(), Some("jwt:expired"));

Structs§

Error
The primary error type for the modo framework.

Enums§

HttpError
A lightweight enum of common HTTP error statuses.

Type Aliases§

Result
A type alias for std::result::Result<T, Error>.