close #745 Added: 403, 404 and 500 exception page added
This commit is contained in:
@ -5,6 +5,9 @@ namespace App\Exceptions;
|
||||
use Exception;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -44,6 +47,10 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
if (env('APP_DEBUG') === false) {
|
||||
return $this->handleExceptions($request, $exception);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
@ -65,4 +72,43 @@ class Handler extends ExceptionHandler
|
||||
|
||||
return redirect()->guest(route('login'));
|
||||
}
|
||||
|
||||
private function handleExceptions($request, $exception)
|
||||
{
|
||||
if ($exception instanceof NotFoundHttpException) {
|
||||
// ajax 404 json feedback
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => 'Not Found'], 404);
|
||||
}
|
||||
|
||||
flash(trans('errors.body.page_not_found'))->error();
|
||||
|
||||
// normal 404 view page feedback
|
||||
return redirect()
|
||||
->back()
|
||||
->withErrors(['msg', trans('errors.body.page_not_found')]);
|
||||
}
|
||||
|
||||
if ($exception instanceof ModelNotFoundException) {
|
||||
// ajax 404 json feedback
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => 'Not Found'], 404);
|
||||
}
|
||||
|
||||
// normal 404 view page feedback
|
||||
return response()->view('errors.404', [], 404);
|
||||
}
|
||||
|
||||
if ($exception instanceof FatalThrowableError) {
|
||||
// ajax 500 json feedback
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => 'Error Page'], 500);
|
||||
}
|
||||
|
||||
// normal 500 view page feedback
|
||||
return response()->view('errors.500', [], 500);
|
||||
}
|
||||
|
||||
return response()->view('errors.500', [], 500);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user