agentleFS
gerard-labsgerard-labs/superpowers-api-platform/skills/api-platform-errors/SKILL.md

api-platform-errors

Skill2 starsChanged 6 months agoMITView on GitHub

Design API Platform 4.3 error handling around RFC 7807 (`application/problem+json`, default in 4.x). Covers `exceptionToStatus` mapping at config / resource / operation level, the 4.3 `errors: [DomainException::class]` flag on operations (auto-documented in OpenAPI), `#[ErrorResource]` + `ProblemExceptionInterface` to turn domain exceptions into documented error resources, custom Error Provider via `#[AsAlias('api_platform.state.error_provider')]`, the HTTP status resolution order (`exceptionToStatus` → `HttpExceptionInterface` → `ProblemExceptionInterface` → defaults → 500), validation error provider (422 + `ConstraintViolationList`), input validation (`Assert\*` on the DTO Input or entity, `UniqueEntity`, validation groups via `validationContext`, custom `Constraint` + `ConstraintValidator`, `collectDenormalizationErrors`, `serialize_payload_fields` for debug, `ValidationException` 4.x namespace move), prod-safe error messages (`setDetail('An unexpected error occurred.')` for 500), stable error `type` URIs (versioned `/errors/v1/...`), and the safety rule of not leaking enumeration details in 401/403. Trigger on "model a domain exception", "RFC 7807", "Problem Detail", "exception to status", "404 vs 410 gone", "validation groups", "Assert constraint", "UniqueEntity", "422 ConstraintViolationList", or "hide error stack trace in prod".

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add errors: [...] on relevant operations so OpenAPI documents the failure cases.

    line 25
  2. Very specific:

    Verify: 422 / 404 / 409 / 410 / 500 all round-trip with the correct Content-Type: application/problem+json.

    line 27

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Platform 4.3 — Errors (RFC 7807, ErrorResource, custom Error Provider)

Use when

  • Designing a new domain exception and how it surfaces in the API.
  • Mapping exception → status code globally or per operation.
  • Hiding 500 stack traces in production while keeping meaningful 4xx errors.
  • Adding errors: [DomainException::class] so OpenAPI documents the failure case.
  • Customizing the error provider to enrich Problem Detail payloads (type, title, instance).

Default workflow

  1. Confirm rfc_7807_compliant_errors: true is set (default in 4.x — Problem Detail format).
  2. For each domain exception, decide: exceptionToStatus mapping, #[ErrorResource] (documented + customizable), or rely on the default.
  3. Add errors: [...] on relevant operations so OpenAPI documents the failure cases.
  4. Implement a custom Error Provider only when you need to enrich the Problem payload (setDetail, type, instance).
  5. Verify: 422 / 404 / 409 / 410 / 500 all round-trip with the correct Content-Type: application/problem+json.

Guardrails

  • No stack traces / file paths in production. A 500 always gets a generic detail.
  • No business details in 401 / 403. Enumeration risk — generic "Access denied".
  • Stable type URIs. Clients pattern-match on them — version them (/errors/v1/stock-unavailable).
  • ValidationException namespace: in 4.x it lives at ApiPlatform\Validator\Exception\ValidationException. The legacy ApiPlatform\Symfony\… path is removed.

Progressive disclosure

  • SKILL.md covers posture and rules.
  • reference.md carries the full config, exceptionToStatus levels, #[ErrorResource] template, custom Error Provider with Error::createFromException, status resolution order, validation error provider, prod-safe pattern, type versioning.

Output contract

  • Domain exceptions either mapped via exceptionToStatus or modeled as #[ErrorResource] with ProblemExceptionInterface.
  • Operations declaring errors: [...] for documented failure modes.
  • Tests asserting application/problem+json Content-Type and the exact type / title / status fields.
  • Production environment configured to hide stack traces.

References

  • reference.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.