/**
  * Creates and return new ApiProblem instance
  *
  * @param  string     $title  title
  * @param  int        $status status code
  * @param  string     $detail description
  * @return ApiProblem
  */
 private function apiProblem($title, $status, $detail = null)
 {
     $problem = new ApiProblem($title, 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html');
     if ($detail) {
         $problem->setDetail($detail);
     }
     $problem->setStatus($status);
     return $problem;
 }
 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);
 }