1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Minepic\Exceptions; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use Illuminate\Auth\Access\AuthorizationException; |
9
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
10
|
|
|
use Illuminate\Validation\ValidationException; |
11
|
|
|
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; |
12
|
|
|
use Minepic\Misc\SplashMessage; |
13
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
14
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
15
|
|
|
|
16
|
|
|
class Handler extends ExceptionHandler |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* A list of the exception types that should not be reported. |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $dontReport = [ |
24
|
|
|
AuthorizationException::class, |
25
|
|
|
HttpException::class, |
26
|
|
|
ModelNotFoundException::class, |
27
|
|
|
ValidationException::class, |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Report or log an exception. |
32
|
|
|
* |
33
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
34
|
|
|
*/ |
35
|
|
|
public function report(Exception $e) |
36
|
|
|
{ |
37
|
|
|
parent::report($e); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Render an exception into an HTTP response. |
42
|
|
|
* |
43
|
|
|
* @param \Illuminate\Http\Request $request |
44
|
|
|
* @param Exception $e |
45
|
|
|
* |
46
|
|
|
* @throws Exception |
47
|
|
|
* |
48
|
|
|
* @return mixed |
49
|
|
|
*/ |
50
|
|
|
public function render($request, Exception $e) |
51
|
|
|
{ |
52
|
|
|
if ($e instanceof NotFoundHttpException) { |
53
|
|
|
return response( |
54
|
|
|
view('public.template.header', [ |
55
|
|
|
'title' => 'Ooops 404! - Minepic', |
56
|
|
|
'description' => 'Error content not found', |
57
|
|
|
'keywords' => '404, error', |
58
|
|
|
'randomMessage' => SplashMessage::get404(), |
59
|
|
|
]). |
60
|
|
|
view('public.errors.404'). |
61
|
|
|
view('public.template.footer'), |
62
|
|
|
404 |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if ($e instanceof NotFoundHttpJsonException) { |
67
|
|
|
return response(['ok' => false, $e->getMessage()], 404); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return parent::render($request, $e); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|