Skip to content

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

  1. errorMessage = error.ExceptionMessage ?? error.Message (BR-WEBAPI-002).
  2. Prefers the exception message; falls back to the generic message.
  3. If error.ExceptionType is non-empty and ends with InvalidDataException, ODataException, or ArgumentException, set the response status to 400 BadRequest (BR-WEBAPI-003).
  4. Suffix match on the type name string, so any namespace qualifies.
  5. Return new ErrorResponse { ErrorCode = (int)responseStatus, ErrorMessage = errorMessage, ErrorId = MessageID, ErrorUrl = MessageIDUrl } (BR-WEBAPI-002).
  6. Constructs a SAIF.API.Responses.ErrorResponse DTO.

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.

Sources

  • src/SAIF.Web.API/ApiResponseHandler.cs