Skip to content

Commit

Permalink
close #745 Added: 403, 404 and 500 exception page added
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Jan 31, 2019
1 parent 39d3c85 commit 4ec5898
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 6 deletions.
46 changes: 46 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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
{
Expand Down Expand Up @@ -44,6 +47,10 @@ public function report(Exception $exception)
*/
public function render($request, Exception $exception)
{
if (env('APP_DEBUG') === false) {
return $this->handleExceptions($request, $exception);
}

return parent::render($request, $exception);
}

Expand All @@ -65,4 +72,43 @@ protected function unauthenticated($request, AuthenticationException $exception)

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);
}
}
24 changes: 24 additions & 0 deletions resources/lang/en-GB/errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return [

'forbidden_access' => 'Forbidden Access',
'error_page' => 'Error Page',
'page_not_found' => 'Page Not Found',

'body' => [
'forbidden_access' => 'Oops! Forbidden Access.',
'error_page' => 'Oops! Something went wrong.',
'page_not_found' => 'Oops! Page not found.',
],

'messages' => [
'forbidden_access' => 'You can not access this page.
Meanwhile, you may <a href=":link">return to dashboard</a>.',
'error_page' => 'We will work on fixing that right away.
Meanwhile, you may <a href=":link">return to dashboard</a>.',
'page_not_found' => 'We could not find the page you were looking for.
Meanwhile, you may <a href=":link">return to dashboard</a>.',
],

];
14 changes: 8 additions & 6 deletions resources/views/errors/403.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
@extends('layouts.admin')

@section('title', 'Forbidden Access')
@section('title', trans('errors.forbidden_access'))

@section('content')
<!-- Default box -->
<div class="box box-success">
<div class="box-body">
<h1>You don't have permission.</h1>
<div class="error-page">
<h2 class="headline text-red">403</h2>

<div class="error-content">
<h3><i class="fa fa-ban text-red"></i> {{ trans('errors.body.forbidden_access') }}</h3>

<p>{!! trans('errors.messages.forbidden_access', ['link' => url('/') ]) !!}</p>
</div>
<!-- /.box-body -->
</div>
@endsection
15 changes: 15 additions & 0 deletions resources/views/errors/404.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@extends('layouts.admin')

@section('title', trans('errors.page_not_found'))

@section('content')
<div class="error-page">
<h2 class="headline text-yellow"> 404</h2>

<div class="error-content">
<h3><i class="fa fa-warning text-yellow"></i> {{ trans('errors.body.page_not_found') }}</h3>

<p>{!! trans('errors.messages.page_not_found', ['link' => url('/')]) !!}</p>
</div>
</div>
@endsection
15 changes: 15 additions & 0 deletions resources/views/errors/500.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@extends('layouts.admin')

@section('title', trans('errors.error_page'))

@section('content')
<div class="error-page">
<h2 class="headline text-red">500</h2>

<div class="error-content">
<h3><i class="fa fa-warning text-red"></i> {{ trans('errors.body.error_page') }}</h3>

<p>{!! trans('errors.messages.error_page', ['link' => url('/') ]) !!}</p>
</div>
</div>
@endsection

0 comments on commit 4ec5898

Please sign in to comment.