Map a Web API error to an ErrorResponse¶
ApiResponseHandler.GetErrorResponse(HttpStatusCode, HttpError) (private) translates a Web API HttpError into the library's normalized ErrorResponse DTO.
| Field | Value |
|---|---|
| Operation ID | OP-04 |
| Trigger | Post-process an API response, step 10. |
| Inputs | HttpStatusCode, HttpError |
| Outputs | SAIF.API.Responses.ErrorResponse |
| Primary components | ApiResponseHandler.GetErrorResponse(HttpStatusCode, HttpError) |
| Entry point | src/SAIF.Web.API/ApiResponseHandler.cs |
Steps¶
errorMessage = error.ExceptionMessage ?? error.Message(BR-WEBAPI-002).- Prefers the exception message; falls back to the generic message.
- If
error.ExceptionTypeis non-empty and ends withInvalidDataException,ODataException, orArgumentException, set the response status to400 BadRequest(BR-WEBAPI-003). - Suffix match on the type name string, so any namespace qualifies.
- Return
new ErrorResponse { ErrorCode = (int)responseStatus, ErrorMessage = errorMessage, ErrorId = MessageID, ErrorUrl = MessageIDUrl }(BR-WEBAPI-002). - Constructs a
SAIF.API.Responses.ErrorResponseDTO.
Process flow¶
flowchart TD
Start(["Called from OP-01 step<br>10"]) --> Msg["errorMessage =<br>ExceptionMessage ??<br>Message"]
Msg --> Suffix{"ExceptionType ends with<br>InvalidDataException /<br>ODataException /<br>ArgumentException?"}
Suffix -->|Yes| Force400["responseStatus = 400<br>BadRequest"]
Suffix -->|No| Keep["Keep original<br>responseStatus"]
Force400 --> Build
Keep --> Build["Build ErrorResponse DTO"]
Build --> End([Return ErrorResponse])
Failure and edge-case behavior¶
- None beyond the suffix-match branch — the method cannot throw for any input shape it handles.
Related documentation¶
Sources¶
src/SAIF.Web.API/ApiResponseHandler.cs