This package provides a RFC7807 Problem details exception listener for Symfony.
Internal, this package uses the models provided by phpro/api-problem
](https://www.github.com/phpro/api-problem).
When an ApiProblemException
is triggered, this bundle will return the correct response.
composer require phpro/api-problem-bundle
// config/bundles.php
return [
// ...
Phpro\ApiProblemBundle\ApiProblemBundle::class => ['all' => true],
];
TODO
- application/problem+json
Use Phpro\ApiProblem\Exception\ApiProblemException
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
SomeController {
/**
* @Route('/some-route', defaults={"_format" = "json"})
*/
someAction() {
throw new ApiProblemException(
new HttpApiProblem('400', 'It aint all bad ...')
);
}
}
When the controller is marked as a "json" format or the request Content-Type
is */json
, this bundle kicks in.
It will transform the exception to following response:
Headers:
Content-Type: application/problem+json
Body:
{
"status": 400,
"type": "http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html",
"title": "Bad Request",
"detail": "It aint all bad ..."
}
Bugs and feature request are tracked on GitHub. Please take a look at our rules before contributing your code.
api-problem-bundle is licensed under the MIT License.