# Fix: API client errors return JSON, not HTML

> Web-audit fix skill for the `json-errors` check (API, SHOULD).

## Goal

Return a JSON error body on client-error API responses so agents can parse the failure.

## Fix

On a client-error API response (4xx), return `Content-Type: application/json` and a JSON object
(for example `{ "error": { "code": "not_found", "message": "..." } }`), not an HTML error page.
Agents cannot recover from a soft-HTML 404. The audit probes a documented OpenAPI 4xx GET when
one exists, otherwise `GET /anc-web-audit-no-such-api`.

## Resources

- [RFC 9457 (problem+json)](https://www.rfc-editor.org/rfc/rfc9457)

## Copy-paste prompt

Paste this into your coding agent. [Your audit](https://anc.dev/audit) adds what it observed for this check:

```text
Goal: Return a JSON error body on client-error API responses so agents can parse the failure
Fix: On a client-error API response (4xx), return `Content-Type: application/json` and a JSON object (for example `{ "error": { "code": "not_found", "message": "..." } }`), not an HTML error page. Agents cannot recover from a soft-HTML 404. The audit probes a documented OpenAPI 4xx GET when one exists, otherwise `GET /anc-web-audit-no-such-api`.
Skill: https://anc.dev/fix/json-errors
Docs: https://www.rfc-editor.org/rfc/rfc9457
```

## Verify

Re-run the audit at [https://anc.dev/audit](https://anc.dev/audit) or call the `audit_website` MCP tool; the `json-errors` check should report `pass`.
