/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } return parent::render($request, $e); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { // If debug is enabled in local environment dump stack trace if (config('app.debug') and app()->environment('local')) { return class_exists('Whoops\\Run') ? $this->whoops($e) : parent::render($request, $e); } // Convert ModelNotFoundException into 404 HttpException if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } // HTTP exceptions are are normally intentionally thrown and its safe to show their message if ($this->isHttpException($e)) { $code = $e->getStatusCode(); $message = $e->getMessage(); if (empty($message)) { $message = isset($this->httpCodes[$code]) ? $this->httpCodes[$code] : $this->httpCodes[500]; } } else { $code = $e->getCode(); if (!isset($this->httpCodes[$code])) { $code = 500; } $message = $this->httpCodes[$code]; } // If a custom view exist use it, otherwise use generic error page $view = view()->exists("errors/{$code}") ? "errors/{$code}" : 'layouts/error'; // Data for the view $data = ['title' => $message, 'code' => $code]; return Response::view($view, $data, $code); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof ModelNotFoundException) { if ($request->ajax()) { return response()->json(['message' => 'Record not found'], 404); } $e = new NotFoundHttpException($e->getMessage(), $e); } return parent::render($request, $e); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } if ($this->shouldUseCustomHandler($e)) { $json = $request->ajax(); return $this->renderExceptionWithWhoops($e, $json); } return parent::render($request, $e); }
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); }
/** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } if (config('app.debug')) { $whoops = new \Whoops\Run(); if ($request->ajax()) { $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler()); } else { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } return response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders()); } return parent::render($request, $e); }
public function showException() { $e = $this->exception; $error = $this->custom_error; if (config('lab1353/errors.report.enabled')) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } $view = ''; $view_error = config('lab1353/errors.report.views_dir') . '.' . $error->code; $view_default = config('lab1353/errors.report.views_dir') . '.' . config('lab1353/errors.report.view_default'); $view = view()->exists($view_error) ? $view_error : $view_default; $data = ['error' => $error, 'e' => $e]; return response()->view($view, $data); } else { return parent::render(response(), $e); } }
/** * Render an exception into a response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } elseif ($e instanceof AuthorizationException) { $e = new HttpException(403, $e->getMessage()); } elseif ($e instanceof ValidationException && $e->response) { return $e->response; } if ($this->isHttpException($e)) { return $this->toIlluminateResponse($this->renderHttpException($e), $e); } else { return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e); } }