本文整理汇总了PHP中Illuminate\Foundation\Exceptions\Handler类的典型用法代码示例。如果您正苦于以下问题:PHP Handler类的具体用法?PHP Handler怎么用?PHP Handler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* 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);
/* COMMENT ABOVE AND UNCOMMENT BELOW TO REDIRECT FOR CUSTOM ERROR HANDLING */
/* if ($this->isHttpException($e)) {
switch ($e->getStatusCode()) {
// not found
case 404:
die("404 Redirect to Page not found here in app/Exceptions/Handler.php");
return redirect()->guest('home');
break;
// internal error
case '500':
die("500 Redirect to internal error page here in app/Exceptions/Handler.php");
return redirect()->guest('home');
break;
default:
return $this->renderHttpException($e);
break;
}
} else {
return parent::render($request, $e);
} */
}
示例2: render
/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @param Exception $exception
*
* @return Response
*/
public function render($request, Exception $exception)
{
if (!$request->is(config('jsonapi.url'))) {
return parent::render($request, $exception);
}
return $this->handle($request, $exception);
}
示例3: render
/**
* 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)
{
switch (get_class($e)) {
case "Swift_TransportException":
case "PDOException":
$errorView = "errors.500_config";
break;
case "ErrorException":
$errorView = "errors.500";
break;
case "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException":
return abort(400);
default:
$errorView = false;
break;
}
if ($errorView) {
// This makes use of a Symfony error handler to make pretty traces.
$SymfonyDisplayer = new SymfonyDisplayer(config('app.debug'));
$FlattenException = FlattenException::create($e);
$SymfonyCss = $SymfonyDisplayer->getStylesheet($FlattenException);
$SymfonyHtml = $SymfonyDisplayer->getContent($FlattenException);
$response = response()->view($errorView, ['exception' => $e, 'error_class' => get_class($e), 'error_css' => $SymfonyCss, 'error_html' => $SymfonyHtml], 500);
return $this->toIlluminateResponse($response, $e);
} else {
return parent::render($request, $e);
}
}
示例4: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
switch ($e) {
case $e instanceof NotFoundHttpException:
return $this->renderException($e);
break;
case $e instanceof ModelNotFoundException:
return $this->renderException($e);
break;
case $e instanceof UnauthorizedException:
return $this->renderException($e);
break;
case $e instanceof NoActiveAccountException:
return $this->renderException($e);
break;
case $e instanceof ConnectionNotAcceptedException:
return $this->renderException($e);
break;
case $e instanceof EmailNotProvidedException:
return $this->renderException($e);
break;
case $e instanceof EmailAlreadyInSystemException:
return $this->renderException($e);
break;
case $e instanceof AlreadySyncedException:
return $this->renderException($e);
break;
case $e instanceof CredentialsDoNotMatchException:
return $this->renderException($e);
break;
default:
return parent::render($request, $e);
}
}
示例5: render
/**
* 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 instanceof NotFoundHttpException) {
return redirect(route('dashboard'));
}
return parent::render($request, $e);
}
示例6: render
/**
* 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')) {
return parent::render($request, $e);
}
if ($e instanceof TokenMismatchException) {
return redirect()->back()->withInput($request->except('_token'))->withErrors('A sua sessão expirou. Tente novamente.');
}
if (!$this->isHttpException($e)) {
$pathInfo = $request->getPathInfo();
$url = $request->url();
$method = $request->method();
$message = $e->getMessage() ?: get_class($e);
$data = ['pathInfo' => $pathInfo, 'url' => $url, 'method' => $method, 'exception' => $message, 'input' => $request->all()];
\Mail::send('emails.notify-webmaster', $data, function ($message) use($url) {
$message->from('no-reply@andremiguelaa.com');
$message->to('andremiguelaa@gmail.com', 'André Ascensão');
$message->subject("Exception at {$url}");
});
}
return parent::render($request, $e);
}
示例7: render
/**
* 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)
{
// LM: 09-02-2015
// See: http://stackoverflow.com/questions/29115184/laravel-catch-tokenmismatchexception
if ($e instanceof \Illuminate\Session\TokenMismatchException) {
// If the erros is a token mismatch
xplog('A token mismatch error happend', __METHOD__);
/* @BOOKMARK: TODO For now just log the user out when a token mismatch happens */
return redirect(route('logout'));
}
// See: https://mattstauffer.co/blog/bringing-whoops-back-to-laravel-5
if ($this->isHttpException($e)) {
// See: https://laracasts.com/discuss/channels/requests/laravel-5-404-page-driving-me-crazy
switch ($e->getStatusCode()) {
case '404':
return \Response::view('errors.custom.404');
break;
/* case '500':
return \Response::view('errors.custom.500');
break; */
/* case '500':
return \Response::view('errors.custom.500');
break; */
default:
return $this->renderHttpException($e);
break;
}
}
if (config('app.debug')) {
return $this->renderExceptionWithWhoops($e);
}
return parent::render($request, $e);
}
示例8: render
/**
* 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 (App::environment() == 'local') {
return parent::render($request, $e);
}
return response()->json(['error' => ['message' => $e->getMessage()]]);
}
示例9: render
/**
* 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 NotFoundHttpException) {
return response()->view('errors/404', [], 404);
}
return parent::render($request, $e);
}
示例10: render
/**
* 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 ModelAlreadyExistsException) {
return redirect()->back()->withErrors([$e->getMessage()]);
}
return parent::render($request, $e);
}
示例11: render
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof ValidationException && $this->isApiRoute($request)) {
return response()->error($exception->validator, 422);
}
return parent::render($request, $exception);
}
示例12: render
/**
* 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)
{
//There should really be a better way to get this into json,
//but this works as well
if ($e instanceof ValidationException) {
$message = "[";
$doneOne = false;
foreach ($e->validator->messages()->all() as $err) {
if (!$doneOne) {
$doneOne = true;
} else {
$message = $message . ",";
}
$message = $message . $err . "\n";
}
$message = $message . "]";
return response($message, 400)->header("Content-Type", "application/json");
} else {
if ($e instanceof HttpException) {
if ($e->getStatusCode() == 404) {
return response(File::get(public_path() . '/index.html'));
}
return $this->renderHttpException($e);
}
}
return parent::render($request, $e);
}
示例13: render
/**
* 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 ($request->is('webhook/*')) {
return $this->getJsonResponseForException($request, $e);
}
return parent::render($request, $e);
}
示例14: render
/**
* 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 (in_array(get_class($e), $this->dontReport)) {
return parent::render($request, $e);
}
return response()->view('errors.500', [], 500);
}
示例15: render
/**
* 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 NotFoundHttpException) {
return redirect()->route('home');
}*/
return parent::render($request, $e);
}