Ejemplo n.º 1
0
 public function __construct(ApiProblem $problem, $status = 200, $headers = array())
 {
     $headers += ['Content-Type' => 'application/problem+json'];
     if (null !== $problem->getStatus()) {
         $headers += ['X-Status-Code' => $problem->getStatus()];
     }
     $data = $problem->asArray();
     parent::__construct($data, $status, $headers);
 }
Ejemplo n.º 2
0
 protected function registerErrorListeners(Application $app)
 {
     $app->error(function (\Exception $e, $code) {
         $problem = new ApiProblem('Unknown error');
         $problem->setDetail($e->getMessage());
         return new JsonResponse($problem->asArray(), $code);
     });
     $app->error(function (ObjectNotFoundException $e) {
         $problem = new ApiProblem('Object not found', 'http://httpstatus.es/404');
         $problem->setDetail($e->getMessage());
         return new JsonResponse($problem->asArray(), Response::HTTP_NOT_FOUND);
     }, 10);
     $app->error(function (NotFoundHttpException $e, $code) {
         $problem = new ApiProblem('Resource not found', 'http://httpstatus.es/404');
         $problem->setDetail($e->getMessage());
         return new JsonResponse($problem->asArray(), $code);
     }, 10);
     $app->error(function (NotAcceptableHttpException $e, $code) {
         $problem = new ApiProblem('No acceptable format available', 'http://httpstatus.es/406');
         $problem->setDetail($e->getMessage());
         return new JsonResponse($problem->asArray(), $code);
     }, 10);
 }