presentation.routers.api.v1.errors.problem_details¶
src.presentation.routers.api.v1.errors.problem_details
¶
RFC 9457 Problem Details for HTTP APIs.
This module implements RFC 9457 (Problem Details for HTTP APIs) using Pydantic models for structured error responses.
RFC 9457: https://www.rfc-editor.org/rfc/rfc9457.html
Exports
ErrorDetail: Individual field-specific error ProblemDetails: RFC 9457 compliant error response schema
Classes¶
ErrorDetail
¶
Bases: BaseModel
Individual field-specific error.
Used for validation errors where multiple fields may have errors.
Attributes:
| Name | Type | Description |
|---|---|---|
field |
str
|
Name of the field with error |
code |
str
|
Machine-readable error code |
message |
str
|
Human-readable error message |
Examples:
>>> error = ErrorDetail(
... field="email",
... code="invalid_email",
... message="Email address format is invalid",
... )
Source code in src/presentation/routers/api/v1/errors/problem_details.py
ProblemDetails
¶
Bases: BaseModel
RFC 9457 Problem Details for HTTP APIs.
Standard error response format providing structured information about errors in HTTP APIs. All fields follow RFC 9457 specification.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
URI reference identifying the problem type |
title |
str
|
Short, human-readable summary of the problem type |
status |
int
|
HTTP status code for this occurrence |
detail |
str
|
Human-readable explanation specific to this occurrence |
instance |
str
|
URI reference identifying the specific occurrence |
errors |
list[ErrorDetail] | None
|
Optional list of field-specific errors (for validation failures) |
trace_id |
str | None
|
Optional request trace ID for debugging |
Examples:
>>> # Validation error
>>> problem = ProblemDetails(
... type="https://api.dashtam.com/errors/validation-error",
... title="Validation Failed",
... status=400,
... detail="The email address format is invalid",
... instance="/api/v1/auth/register",
... errors=[
... ErrorDetail(
... field="email",
... code="invalid_email",
... message="Email address format is invalid",
... )
... ],
... trace_id="550e8400-e29b-41d4-a716-446655440000",
... )
>>>
>>> # Not found error
>>> problem = ProblemDetails(
... type="https://api.dashtam.com/errors/not-found",
... title="Resource Not Found",
... status=404,
... detail="User with ID '123' does not exist",
... instance="/api/v1/users/123",
... trace_id="550e8400-e29b-41d4-a716-446655440000",
... )