presentation.routers.api.v1.errors.error_response_builder¶
src.presentation.routers.api.v1.errors.error_response_builder
¶
Error response builder for RFC 9457 Problem Details.
This module provides utilities to build RFC 9457 compliant error responses from application layer errors.
Exports
ErrorResponseBuilder: Utility class for building RFC 9457 responses
Classes¶
ErrorResponseBuilder
¶
Build RFC 9457 Problem Details error responses.
Converts application layer errors into standardized RFC 9457 JSON responses with appropriate HTTP status codes and structured error information.
Example
error = ApplicationError( ... code=ApplicationErrorCode.COMMAND_VALIDATION_FAILED, ... message="Email is invalid", ... ) response = ErrorResponseBuilder.from_application_error( ... error=error, ... request=request, ... trace_id="550e8400-e29b-41d4-a716-446655440000", ... )
Source code in src/presentation/routers/api/v1/errors/error_response_builder.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
Functions¶
from_application_error
staticmethod
¶
Convert ApplicationError to RFC 9457 JSON response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
ApplicationError
|
Application layer error to convert |
required |
request
|
Request
|
FastAPI Request object (for instance URL) |
required |
trace_id
|
str
|
Request trace ID for debugging |
required |
Returns:
| Type | Description |
|---|---|
JSONResponse
|
JSONResponse with RFC 9457 ProblemDetails content |
Example
error = ApplicationError( ... code=ApplicationErrorCode.NOT_FOUND, ... message="User not found", ... ) response = ErrorResponseBuilder.from_application_error( ... error, request, trace_id ... )
Returns 404 with ProblemDetails JSON¶