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); }