Skip to content
This repository was archived by the owner on Jul 4, 2018. It is now read-only.

Commit ebd8723

Browse files
committed
Errors handler
1 parent 1924dc8 commit ebd8723

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/Exceptions/Handler.php

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Database\Eloquent\ModelNotFoundException;
99
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
1010
use Symfony\Component\HttpKernel\Exception\HttpException;
11+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1112

1213
class Handler extends ExceptionHandler
1314
{
@@ -45,6 +46,22 @@ public function report(Exception $e)
4546
*/
4647
public function render($request, Exception $e)
4748
{
49+
if ($this->isNotFound($e)) {
50+
return response(view('error')->render(), 404);
51+
}
52+
4853
return parent::render($request, $e);
4954
}
55+
56+
/**
57+
* Check whether is not found exception.
58+
*
59+
* @param Exception $ex
60+
* @return bool
61+
*/
62+
protected function isNotFound(Exception $ex)
63+
{
64+
return $ex instanceof NotFoundHttpException
65+
|| $ex instanceof ModelNotFoundException;
66+
}
5067
}

resources/views/error.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Views file for errors handler.
4+
*
5+
* @author Vladimir Kuprienko <vldmr.kuprienko@gmail.com>
6+
*/
7+
?>
8+
<h1>404</h1>
9+
<p>Page not found.</p>

0 commit comments

Comments
 (0)