Tweak rendering HTTP exceptions
This commit is contained in:
parent
53435e27b4
commit
89bc8d4ccc
|
|
@ -85,6 +85,40 @@ class Handler extends ExceptionHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the given HttpException.
|
||||||
|
*
|
||||||
|
* @param \Symfony\Component\HttpKernel\Exception\HttpException $e
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
protected function renderHttpException(HttpException $e)
|
||||||
|
{
|
||||||
|
$status = $e->getStatusCode();
|
||||||
|
$message = $e->getMessage();
|
||||||
|
|
||||||
|
// Get message from exception itself > translation > standard status texts
|
||||||
|
if (! $message) {
|
||||||
|
if (trans()->has($transKey = "errors.http.msg-{$status}")) {
|
||||||
|
$message = trans($transKey);
|
||||||
|
} else {
|
||||||
|
$message = array_get(Response::$statusTexts, $status, "Status code: $status");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request()->ajax()) {
|
||||||
|
return response($message, $status, $e->getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view()->exists("errors.{$status}")) {
|
||||||
|
return response()->view("errors.{$status}", ['exception' => $e], $status, $e->getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->view('errors.http', [
|
||||||
|
'title' => "HTTP {$status}",
|
||||||
|
'message' => $message
|
||||||
|
], $status, $e->getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an exception using Whoops.
|
* Render an exception using Whoops.
|
||||||
*
|
*
|
||||||
|
|
@ -97,28 +131,28 @@ class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
$whoops = new \Whoops\Run;
|
$whoops = new \Whoops\Run;
|
||||||
$handler = (request()->isMethod('GET')) ?
|
$handler = (request()->isMethod('GET')) ?
|
||||||
new \Whoops\Handler\PrettyPageHandler : new \Whoops\Handler\PlainTextHandler;
|
new \Whoops\Handler\PrettyPageHandler : new \Whoops\Handler\PlainTextHandler;
|
||||||
$whoops->pushHandler($handler);
|
$whoops->pushHandler($handler);
|
||||||
|
|
||||||
return new Response(
|
return response($whoops->handleException($e), $code, $headers);
|
||||||
$whoops->handleException($e),
|
|
||||||
$code,
|
|
||||||
$headers
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an exception in a short word.
|
* Render an exception with error messages only.
|
||||||
*
|
*
|
||||||
* @param Exception $e
|
* @param Exception $e
|
||||||
|
* @param int $code
|
||||||
|
* @param array $headers
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
protected function renderExceptionInBrief(Exception $e)
|
protected function renderExceptionInBrief(Exception $e, $code = 200, $headers = [])
|
||||||
{
|
{
|
||||||
if (request()->isMethod('GET') && !request()->ajax()) {
|
if (request()->ajax()) {
|
||||||
return response()->view('errors.exception', ['message' => $e->getMessage()]);
|
return response($e->getMessage(), $code, $headers);
|
||||||
} else {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response()->view('errors.exception', [
|
||||||
|
'message' => $e->getMessage()
|
||||||
|
], $code, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
resources/views/errors/http.blade.php
Normal file
11
resources/views/errors/http.blade.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
@extends('errors.general')
|
||||||
|
|
||||||
|
@section('title', $title)
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>{{ $title }}
|
||||||
|
@include('setup.wizard.language')
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<p>{{ trans('errors.exception.detail', ['msg' => $message]) }}</p>
|
||||||
|
@endsection
|
||||||
Loading…
Reference in New Issue
Block a user