1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ship\Engine\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Auth\AuthenticationException; |
7
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
8
|
|
|
use Illuminate\Foundation\Exceptions\Handler as LaravelExceptionHandler; |
9
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ShipExceptionsHandler |
13
|
|
|
* |
14
|
|
|
* A.K.A (app/Exceptions/Handler.php) |
15
|
|
|
* |
16
|
|
|
* @author Mahmoud Zalt <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class ShipExceptionsHandler extends LaravelExceptionHandler |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* A list of the exception types that should not be reported. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $dontReport = [ |
27
|
|
|
\Symfony\Component\HttpKernel\Exception\HttpException::class, |
28
|
|
|
// \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
29
|
|
|
// \Illuminate\Auth\AuthenticationException::class, |
30
|
|
|
// \Illuminate\Auth\Access\AuthorizationException::class, |
31
|
|
|
// \Illuminate\Session\TokenMismatchException::class, |
32
|
|
|
// \Illuminate\Validation\ValidationException::class, |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Report or log an exception. |
37
|
|
|
* |
38
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
39
|
|
|
* |
40
|
|
|
* @param \Exception $exception |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function report(Exception $exception) |
45
|
|
|
{ |
46
|
|
|
parent::report($exception); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Render an exception into an HTTP response. |
51
|
|
|
* |
52
|
|
|
* @param \Illuminate\Http\Request $request |
53
|
|
|
* @param \Exception $exception |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Http\Response |
56
|
|
|
*/ |
57
|
|
|
public function render($request, Exception $exception) |
58
|
|
|
{ |
59
|
|
|
if ($exception instanceof ModelNotFoundException) { |
60
|
|
|
$exception = new NotFoundHttpException($exception->getMessage(), $exception); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// .. |
64
|
|
|
|
65
|
|
|
return parent::render($request, $exception); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Convert an authentication exception into an unauthenticated response. |
70
|
|
|
* |
71
|
|
|
* @param \Illuminate\Http\Request $request |
72
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\Http\Response |
75
|
|
|
*/ |
76
|
|
|
protected function unauthenticated($request, AuthenticationException $exception) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
if ($request->expectsJson()) { |
79
|
|
|
return response()->json(['error' => 'Unauthenticated.'], 401); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return redirect()->guest('login'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.