Merge pull request #721 from nabeelio/715-Error-Page-Skins
Use theme in error handlers #715
This commit is contained in:
commit
71c09aaeb1
@ -5,6 +5,7 @@ namespace App\Exceptions;
|
|||||||
use App\Exceptions\Converters\GenericExceptionAbstract;
|
use App\Exceptions\Converters\GenericExceptionAbstract;
|
||||||
use App\Exceptions\Converters\SymfonyException;
|
use App\Exceptions\Converters\SymfonyException;
|
||||||
use App\Exceptions\Converters\ValidationException;
|
use App\Exceptions\Converters\ValidationException;
|
||||||
|
use App\Http\Middleware\SetActiveTheme;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Auth\Access\AuthorizationException;
|
use Illuminate\Auth\Access\AuthorizationException;
|
||||||
use Illuminate\Auth\AuthenticationException;
|
use Illuminate\Auth\AuthenticationException;
|
||||||
@ -17,7 +18,6 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use Illuminate\Validation\ValidationException as IlluminateValidationException;
|
use Illuminate\Validation\ValidationException as IlluminateValidationException;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Whoops\Handler\HandlerInterface;
|
use Whoops\Handler\HandlerInterface;
|
||||||
@ -54,8 +54,8 @@ class Handler extends ExceptionHandler
|
|||||||
return $this->handleApiError($request, $exception);
|
return $this->handleApiError($request, $exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exception instanceof AbstractHttpException
|
(new SetActiveTheme())->setTheme($request);
|
||||||
&& $exception->getStatusCode() === 403) {
|
if ($exception instanceof AbstractHttpException && $exception->getStatusCode() === 403) {
|
||||||
return redirect()->guest('login');
|
return redirect()->guest('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,38 +119,13 @@ class Handler extends ExceptionHandler
|
|||||||
{
|
{
|
||||||
if ($request->expectsJson() || $request->is('api/*')) {
|
if ($request->expectsJson() || $request->is('api/*')) {
|
||||||
$error = new Unauthenticated();
|
$error = new Unauthenticated();
|
||||||
|
|
||||||
return $error->getResponse();
|
return $error->getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->guest('login');
|
return redirect()->guest('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the given HttpException.
|
|
||||||
*
|
|
||||||
* @param AbstractHttpException $e
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response|Response
|
|
||||||
*/
|
|
||||||
protected function renderHttpException(HttpExceptionInterface $e)
|
|
||||||
{
|
|
||||||
$status = $e->getStatusCode();
|
|
||||||
view()->replaceNamespace('errors', [
|
|
||||||
resource_path('views/layouts/'.setting('general.theme', 'default').'/errors'),
|
|
||||||
resource_path('views/errors'),
|
|
||||||
__DIR__.'/views',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (view()->exists("errors::{$status}")) {
|
|
||||||
return response()->view("errors::{$status}", [
|
|
||||||
'exception' => $e,
|
|
||||||
'SKIN_NAME' => setting('general.theme', 'default'),
|
|
||||||
], $status, $e->getHeaders());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->convertExceptionToResponse($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignition error page integration
|
* Ignition error page integration
|
||||||
*/
|
*/
|
||||||
|
@ -13,23 +13,42 @@ use Illuminate\Support\Facades\Log;
|
|||||||
*/
|
*/
|
||||||
class SetActiveTheme implements Middleware
|
class SetActiveTheme implements Middleware
|
||||||
{
|
{
|
||||||
|
private static $skip = [
|
||||||
|
'admin',
|
||||||
|
'admin/*',
|
||||||
|
'api',
|
||||||
|
'api/*',
|
||||||
|
'importer',
|
||||||
|
'importer/*',
|
||||||
|
'install',
|
||||||
|
'install/*',
|
||||||
|
'update',
|
||||||
|
'update/*',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the request
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function handle(Request $request, Closure $next)
|
public function handle(Request $request, Closure $next)
|
||||||
{
|
{
|
||||||
$skip = [
|
$this->setTheme($request);
|
||||||
'admin',
|
return $next($request);
|
||||||
'admin/*',
|
}
|
||||||
'api',
|
|
||||||
'api/*',
|
|
||||||
'importer',
|
|
||||||
'importer/*',
|
|
||||||
'install',
|
|
||||||
'install/*',
|
|
||||||
'update',
|
|
||||||
'update/*',
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($request->is($skip)) {
|
/**
|
||||||
return $next($request);
|
* Set the theme for the current middleware
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
*/
|
||||||
|
public function setTheme(Request $request)
|
||||||
|
{
|
||||||
|
if ($request->is(self::$skip)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -42,7 +61,5 @@ class SetActiveTheme implements Middleware
|
|||||||
if (!empty($theme)) {
|
if (!empty($theme)) {
|
||||||
Theme::set($theme);
|
Theme::set($theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user