problem-details-rfc9457
Skill35 starsChanged 5 months agoMITView on GitHub
Use when generating error responses, exception listeners, or custom exceptions in a Symfony API. Defines RFC 9457 (problem+json) error format, mapping domain exceptions to HTTP status codes, and a single kernel exception listener. Use when the task mentions error handling, exception listener, error response, or problem details.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- rrezartprebreza/spring-boot-skillstheir own version, first seen Aug 7, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- rrezartprebreza/spring-boot-skills★ 344same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- api-platform-resourcesSkill
- bundle-organizationSkill
- console-commandsSkill
- doctrine-migrationsSkill
- doctrine-ormSkill
- doctrine-query-optimizationSkill
- domain-driven-designSkill
- dto-and-validationSkill
- hexagonal-architectureSkill
- jwt-authenticationSkill
- layered-architectureSkill
- messenger-asyncSkill
- rest-controller-conventionsSkill
- security-authenticationSkill
- testing-pyramidSkill
- transactional-patternsSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Every error response is application/problem+json per RFC 9457:
- Distinctive: line 159
Never echo SQL, file paths, or class names to the client.
≈ “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
RFC 9457 Problem Details (Symfony)
The format
Every error response is application/problem+json per RFC 9457:
{
"type": "https://api.example.com/problems/order-not-found",
"title": "Order not found",
"status": 404,
"detail": "No order exists with id 018f...",
"instance": "/api/orders/018f...",
"errors": [
{ "field": "items", "message": "This collection should contain 1 element or more." }
]
}type— a stable URI identifying the problem class (dereferenceable docs ideally).title— short, human-readable, same for every occurrence of this type.status— the HTTP status code, duplicated in the body.detail— specific to this occurrence.instance— the request URI that produced it.- Extension members (
errors,traceId, …) are allowed and encouraged.
Domain exceptions carry their own HTTP semantics
Define a base exception that knows its status and problem type. Throw it from services/domain; never build error JSON in a controller.
abstract class DomainException extends \RuntimeException
{
abstract public function statusCode(): int;
abstract public function problemType(): string;
public function title(): string
{
return (new \ReflectionClass($this))->getShortName();
}
}
final class OrderNotFoundException extends DomainException
{
public function __construct(Uuid $id)
{
parent::__construct("No order exists with id {$id->toRfc4122()}");
}
public function statusCode(): int { return Response::HTTP_NOT_FOUND; }
public function problemType(): string { return 'https://api.example.com/problems/order-not-found'; }
public function title(): string { return 'Order not found'; }
}One exception listener, not try/catch everywhere
#[AsEventListener(event: KernelEvents::EXCEPTION, priority: 0)]
final class ProblemDetailsExceptionListener
{
public function __construct(
private readonly LoggerInterface $logger,
#[Autowire('%kernel.debug%')] private readonly bool $debug,
) {}
public function __invoke(ExceptionEvent $event): void
{
$e = $event->getThrowable();
$request = $event->getRequest();
$problem = match (true) {
$e instanceof DomainException => $this->fromDomain($e, $request),
$e instanceof ValidationFailedException => $this->fromValidation($e, $request),
$e instanceof HttpExceptionInterface => $this->fromHttp($e, $request),
default => $this->fromUnexpected($e, $request),
};
if ($problem['status'] >= 500) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
$event->setResponse(new JsonResponse(
$problem,
$problem['status'],
['Content-Type' => 'application/problem+json'],
));
}
private function fromDomain(DomainException $e, Request $request): array
{
return [
'type' => $e->problemType(),
'title' => $e->title(),
'status' => $e->statusCode(),
'detail' => $e->getMessage(),
'instance' => $request->getPathInfo(),
];
}
private function fromValidation(ValidationFailedException $e, Request $request): array
{
$errors = [];
foreach ($e->getViolations() as $v) {
$errors[] = ['field' => $v->getPropertyPath(), 'message' => $v->getMessage()];
}
return [
'type' => 'https://api.example.com/problems/validation-error',
'title' => 'Validation failed',
'status' => Response::HTTP_UNPROCESSABLE_ENTITY,
'detail' => 'The request payload did not pass validation.',
'instance' => $request->getPathInfo(),
'errors' => $errors,
];
}
private function fromHttp(HttpExceptionInterface $e, Request $request): array
{
return [
'type' => 'about:blank',
'title' => Response::$statusTexts[$e->getStatusCode()] ?? 'Error',
'status' => $e->getStatusCode(),
'detail' => $e->getMessage(),
'instance' => $request->getPathInfo(),
];
}
private function fromUnexpected(\Throwable $e, Request $request): array
{
return [
'type' => 'about:blank',
'title' => 'Internal Server Error',
'status' => Response::HTTP_INTERNAL_SERVER_ERROR,
// Never leak internals in prod.
'detail' => $this->debug ? $e->getMessage() : 'An unexpected error occurred.',
'instance' => $request->getPathInfo(),
];
}
}Don't leak internals
- In
prod, thedetailfor 5xx must be generic — never the exception message or stack trace. - Log the full exception server-side with a
traceId; return that id so support can correlate. - Never echo SQL, file paths, or class names to the client.
API Platform note
API Platform 4 already emits problem+json. You only need this listener for non-API-Platform controllers, or to customize the problem type/extensions. Map domain exceptions to status codes via config/packages/api_platform.yaml exception_to_status.
Gotchas
- Agent builds
['error' => '...']ad-hoc JSON — use the RFC 9457 shape withtype/title/status/detail/instance. - Agent sets
Content-Type: application/jsonfor errors — useapplication/problem+json. - Agent
try/catches in each controller — centralize in oneKernelEvents::EXCEPTIONlistener. - Agent leaks
$e->getMessage()/ stack traces on 5xx in prod — gate behindkernel.debug. - Agent uses HTTP
400for validation errors — Symfony convention is422 Unprocessable Entity. - Agent forgets to log 5xx — log server-side; only the safe summary goes to the client.
- Agent reinvents an exception hierarchy per feature — extend the shared
DomainExceptionbase.
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.

