# Typed error bodies (https://effetch.pages.dev/docs/errors/error-bodies)

APIs usually explain an error in its body, such as
`{ "code": "not_found" }`. This page shows how to give Effetch a schema for
that body, so that `HttpError.body` is decoded and typed.

## Give a schema for the error body

You can set the schema in two places:

- `defaultError`, on the client, applies to every call;
- `error`, on a call or an [endpoint](https://effetch.pages.dev/docs/endpoints), replaces it.

## Read the body

`body` is the decoded body, or `undefined` if it didn't match the schema.
Without a schema, it's the parsed JSON. Reading it never fails the call, and
the raw body is always on `text`.

`Fetch.HttpError.With<B>` is the type of an `HttpError` whose `body` is `B`,
for your own function signatures.

## What's next

- [Catch errors](https://effetch.pages.dev/docs/errors/catching): read the typed body in an
  `HttpError` handler.
- [Errors by status](https://effetch.pages.dev/docs/errors/status-errors): turn a status and its body
  into your own error.
- [Client configuration](https://effetch.pages.dev/docs/clients/configuration): set `defaultError` with the
  client's other options.