public function renderAsRestAPI($request, \Exception $e) { if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } elseif ($e instanceof AuthorizationException) { $e = new HttpException(403, $e->getMessage()); } elseif ($e instanceof ValidationException && $e->getResponse()) { return $e->getResponse(); } $fe = FlattenException::create($e); $data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."]; return JsonResponse::create($data, 500); }
function getResponse($request) { $response = parent::getResponse($request); $response->headers['Accept'] = is_array($this->accept) ? implode(',', $this->accept) : $this->accept; return $response; }