Skip to main content

IntoProblem

Trait IntoProblem 

Source
pub trait IntoProblem {
    // Required method
    fn into_problem(self) -> Problem;
}
Expand description

Convert a value into an RFC 7807 Problem.

Implement this trait on your application’s error types to enable automatic conversion into structured problem responses.

§Example

use rust_rfc7807::{IntoProblem, Problem};

enum AppError {
    UserNotFound(u64),
    Unauthorized,
}

impl IntoProblem for AppError {
    fn into_problem(self) -> Problem {
        match self {
            AppError::UserNotFound(id) => Problem::not_found()
                .title("User not found")
                .detail(format!("No user with ID {id}"))
                .code("USER_NOT_FOUND"),
            AppError::Unauthorized => Problem::unauthorized()
                .title("Unauthorized")
                .code("UNAUTHORIZED"),
        }
    }
}

Required Methods§

Source

fn into_problem(self) -> Problem

Convert this value into a Problem instance.

Implementors§