Crate error_envelope

Crate error_envelope 

Source
Expand description

A tiny, framework-agnostic error envelope for HTTP APIs.

This crate provides a structured error envelope that standardizes error responses across HTTP services with fields for:

  • Stable machine-readable codes
  • Human-readable messages
  • Structured details
  • Trace IDs for debugging
  • Retry signals for resilience

§Example

use error_envelope::{Error, Code};

let err = Error::not_found("User not found")
    .with_details(serde_json::json!({"user_id": "123"}))
    .with_trace_id("abc-def-123");

assert_eq!(err.code, Code::NotFound);
assert_eq!(err.status, 404);

Structs§

Error
Structured error envelope for HTTP APIs.

Enums§

Code
Machine-readable error codes that remain stable across releases.

Functions§

bad_requestf
Creates a bad request error with formatted message.
conflictf
Creates a conflict error with formatted message.
forbiddenf
Creates a forbidden error with formatted message.
from
Maps arbitrary errors into an Error.
internalf
Creates an internal server error with formatted message.
is
Checks if an error has the given code.
not_foundf
Creates a not found error with formatted message.
timeoutf
Creates a timeout error with formatted message.
unauthorizedf
Creates an unauthorized error with formatted message.
unavailablef
Creates an unavailable error with formatted message.
validation
Creates a validation error with field-level details.

Type Aliases§

FieldErrors
Field-level validation errors.