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".
In this repository52 other files it gives its agents.
- api-platform-dto-resourcesSkill
- api-platform-file-uploadSkill
- api-platform-filtersSkill
- api-platform-identifiersSkill
- api-platform-mcpSkill
- api-platform-mutatorsSkill
- api-platform-openapiSkill
- api-platform-paginationSkill
- api-platform-performanceSkill
- api-platform-resilienceSkill
- api-platform-resourcesSkill
- api-platform-securitySkill
- api-platform-serializationSkill
- api-platform-state-processorsSkill
- api-platform-state-providersSkill
- api-platform-testsSkill
- api-platform-upgradeSkill
- api-platform-userSkill
- api-platform-versioningSkill
- bootstrap-checkSkill
- brainstormingSkill
- config-env-parametersSkill
- controller-cleanupSkill
- cqrs-and-handlersSkill
- daily-workflowSkill
- doctrine-batch-processingSkill
- doctrine-fetch-modesSkill
- doctrine-fixtures-foundrySkill
- doctrine-migrationsSkill
- doctrine-relationsSkill
- doctrine-transactionsSkill
- effective-contextSkill
- executing-plansSkill
- functional-testsSkill
- interfaces-and-autowiringSkill
- makefile-disciplineSkill
- messenger-retry-failuresSkill
- ports-and-adaptersSkill
- quality-checksSkill
- rate-limitingSkill
- runner-selectionSkill
- strategy-patternSkill
- symfony-cacheSkill
- symfony-messengerSkill
- symfony-schedulerSkill
- symfony-votersSkill
- tdd-with-pestSkill
- tdd-with-phpunitSkill
- test-doubles-mockingSkill
- using-symfony-superpowersSkill
- value-objects-and-dtosSkill
- writing-plansSkill
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
- Very specific: line 25
Add errors: [...] on relevant operations so OpenAPI documents the failure cases.
- Very specific: line 27
Verify: 422 / 404 / 409 / 410 / 500 all round-trip with the correct Content-Type: application/problem+json.
≈ “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.
Files
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
- Confirm
rfc_7807_compliant_errors: trueis set (default in 4.x — Problem Detail format). - For each domain exception, decide:
exceptionToStatusmapping,#[ErrorResource](documented + customizable), or rely on the default. - Add
errors: [...]on relevant operations so OpenAPI documents the failure cases. - Implement a custom Error Provider only when you need to enrich the Problem payload (
setDetail,type,instance). - 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
typeURIs. Clients pattern-match on them — version them (/errors/v1/stock-unavailable). ValidationExceptionnamespace: in 4.x it lives atApiPlatform\Validator\Exception\ValidationException. The legacyApiPlatform\Symfony\…path is removed.
Progressive disclosure
SKILL.mdcovers posture and rules.reference.mdcarries the full config,exceptionToStatuslevels,#[ErrorResource]template, custom Error Provider withError::createFromException, status resolution order, validation error provider, prod-safe pattern, type versioning.
Output contract
- Domain exceptions either mapped via
exceptionToStatusor modeled as#[ErrorResource]withProblemExceptionInterface. - Operations declaring
errors: [...]for documented failure modes. - Tests asserting
application/problem+jsonContent-Type and the exacttype/title/statusfields. - Production environment configured to hide stack traces.
References
reference.md
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
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.

