---
title: Map a Web API error to an ErrorResponse
summary: Translate an HttpError into the library's normalized ErrorResponse DTO, including the 400-classification rule.
status: draft
owner: andmil
last_reviewed: 2026-09-15
library: SAIF.Web.API
reference_type: package
operation_id: OP-04
trigger: OP-01 (Post-process an API response), step 10.
---

# 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](op-01-post-process-an-api-response.md), 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](../business-rules.md#br-webapi-002-normalize-non-success-responses-into-errorresponse)).
   - Prefers the exception message; falls back to the generic message.
2. If `error.ExceptionType` is non-empty and ends with `InvalidDataException`, `ODataException`, or `ArgumentException`, set the response status to `400 BadRequest` ([BR-WEBAPI-003](../business-rules.md#br-webapi-003-client-fault-exception-types-map-to-400-bad-request)).
   - Suffix match on the **type name string**, so any namespace qualifies.
3. Return `new ErrorResponse { ErrorCode = (int)responseStatus, ErrorMessage = errorMessage, ErrorId = MessageID, ErrorUrl = MessageIDUrl }` ([BR-WEBAPI-002](../business-rules.md#br-webapi-002-normalize-non-success-responses-into-errorresponse)).
   - Constructs a `SAIF.API.Responses.ErrorResponse` DTO.

## Process flow

```mermaid
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
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `src/SAIF.Web.API/ApiResponseHandler.cs`
