Skip to main content

Module error

Module error 

Source
Expand description

Standard API error types for all api-bones services.

All services serialize errors into ApiError before sending an HTTP response. The wire format conforms to RFC 9457 — Problem Details for HTTP APIs:

{
  "type": "urn:api-bones:error:resource-not-found",
  "title": "Resource Not Found",
  "status": 404,
  "detail": "Booking 123 not found",
  "instance": "urn:uuid:01234567-89ab-cdef-0123-456789abcdef"
}

Content-Type: application/problem+json

§no_std + alloc limitations

ErrorTypeMode is available under the alloc feature (its fields use String), but the global accessors error_type_mode and set_error_type_mode require the std feature because they rely on std::sync::RwLock and std::env::var.

In a no_std + alloc environment you can still construct an ErrorTypeMode value and call ErrorTypeMode::render directly, but the automatic environment-variable resolution is unavailable.

Structs§

ApiError
RFC 9457 Problem Details error response.
ApiErrorBuilder
Typestate builder for ApiError.
ProblemJson
RFC 7807 / 9457 Problem Details response body with optional extension members.
ValidationError
A single field-level validation error, used in ApiError::errors.

Enums§

ErrorCode
Machine-readable error code included in every API error response.
ErrorTypeMode
How the RFC 9457 type field is rendered for ErrorCode.

Traits§

HttpError
Implement this trait on domain error types to get a blanket From implementation into ApiError for free.

Functions§

error_type_mode
Returns the active ErrorTypeMode.
set_error_type_mode
Override the error type mode programmatically (call once at application startup).
urn_namespace
Returns the active URN namespace (convenience wrapper around error_type_mode). Only meaningful when in ErrorTypeMode::Urn mode.