1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* @Project Expression project.displayName is undefined on line 5, column 35 in Templates/Licenses/license-default.txt. |
6
|
|
|
* @Copyright Djoudi |
7
|
|
|
* @Created 2017-02-21 |
8
|
|
|
* @Filename H5PExceptionHandler.php |
9
|
|
|
* @Description |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Djoudi\LaravelH5p\Exceptions; |
14
|
|
|
|
15
|
|
|
use Exception; |
16
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
17
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
18
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
19
|
|
|
|
20
|
|
|
class H5PExceptionHandler extends ExceptionHandler |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* A list of the exception types that should not be reported. |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $dontReport = [ |
28
|
|
|
HttpException::class, |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Report or log an exception. |
33
|
|
|
* |
34
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
35
|
|
|
* |
36
|
|
|
* @param \Exception $e |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function report(Exception $e) |
41
|
|
|
{ |
42
|
|
|
return parent::report($e); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Render an exception into an HTTP response. |
47
|
|
|
* |
48
|
|
|
* @param \Illuminate\Http\Request $request |
49
|
|
|
* @param $e |
50
|
|
|
* |
51
|
|
|
* @return \Illuminate\Http\Response |
52
|
|
|
*/ |
53
|
|
|
public function render($request, Exception $e) |
54
|
|
|
{ |
55
|
|
|
switch ($e) { |
56
|
|
|
|
57
|
|
|
case $e instanceof ModelNotFoundException: |
58
|
|
|
|
59
|
|
|
return $this->renderException($e); |
60
|
|
|
break; |
|
|
|
|
61
|
|
|
|
62
|
|
|
case $e instanceof H5PException: |
63
|
|
|
|
64
|
|
|
return $this->renderException($e); |
65
|
|
|
break; |
66
|
|
|
|
67
|
|
|
default: |
68
|
|
|
|
69
|
|
|
return parent::render($request, $e); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function renderException($e) |
74
|
|
|
{ |
75
|
|
|
switch ($e) { |
76
|
|
|
|
77
|
|
|
case $e instanceof ModelNotFoundException: |
78
|
|
|
return response()->view('errors.404', [], 404); |
79
|
|
|
break; |
|
|
|
|
80
|
|
|
|
81
|
|
|
case $e instanceof H5PException: |
82
|
|
|
return response()->view('errors.friendly'); |
83
|
|
|
break; |
84
|
|
|
default: |
85
|
|
|
return (new SymfonyDisplayer(config('app.debug'))) |
|
|
|
|
86
|
|
|
->createResponse($e); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|