Skip to content

Commit b5e0c8e

Browse files
committed
docs: document DecodeError in the errors reference
Adds DecodeError to the exception-tree diagram and a new subsection covering when it's raised, what fields it carries, and a minimal except snippet.
1 parent 2016e49 commit b5e0c8e

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎docs/errors.md‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ ClientError (catch-all for anything httpware raises)
2626
│ ├── InternalServerError (500)
2727
│ └── ServiceUnavailableError (503)
2828
├── RetryBudgetExhaustedError (a retry was needed but the budget refused)
29-
└── BulkheadFullError (acquire_timeout elapsed before a slot opened)
29+
├── BulkheadFullError (acquire_timeout elapsed before a slot opened)
30+
└── DecodeError (response_model= decoder failed; HTTP call itself succeeded)
3031
```
3132

3233
## Status-to-exception mapping
@@ -128,6 +129,32 @@ except RetryBudgetExhaustedError as exc:
128129
)
129130
```
130131

132+
## `DecodeError`
133+
134+
`DecodeError` is raised when `response_model=` is set on a request and the active `ResponseDecoder` failed to parse the response body. The HTTP call itself succeeded — status was 2xx/3xx and the transport delivered the body intact — but the body could not be coerced into the requested model. The exception is raised independently of which decoder is in use (`PydanticDecoder`, `MsgspecDecoder`, or a third-party adapter), so `except httpware.ClientError` is sufficient to cover the response-model decode path.
135+
136+
Fields:
137+
138+
- `response: httpx2.Response` — the response whose body failed to decode. Status, headers, and the originating `request` are all available via `exc.response.*`.
139+
- `model: type` — the type that was passed as `response_model=`.
140+
- `original: BaseException` — the underlying library exception (e.g., `pydantic.ValidationError`, `msgspec.ValidationError`, `msgspec.DecodeError`). Also available via `exc.__cause__`.
141+
142+
```python
143+
from httpware import AsyncClient, DecodeError
144+
145+
146+
try:
147+
user = await client.get("/users/1", response_model=User)
148+
except DecodeError as exc:
149+
_LOGGER.error(
150+
"decode failed for %s into %s: %s",
151+
exc.response.request.url,
152+
exc.model.__name__,
153+
exc.original,
154+
)
155+
raise
156+
```
157+
131158
## See also
132159

133160
- **[Resilience reference](resilience.md)** — `AsyncRetry`, `RetryBudget`, `AsyncBulkhead` parameter tables.

0 commit comments

Comments
 (0)