1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
7
|
|
|
|
8
|
|
|
class Handler extends ExceptionHandler |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* A list of the exception types that should not be reported. |
12
|
|
|
* |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
protected $dontReport = [ |
16
|
|
|
\Illuminate\Auth\AuthenticationException::class, |
17
|
|
|
\Illuminate\Auth\Access\AuthorizationException::class, |
18
|
|
|
\Symfony\Component\HttpKernel\Exception\HttpException::class, |
19
|
|
|
\Illuminate\Database\Eloquent\ModelNotFoundException::class, |
20
|
|
|
\Illuminate\Session\TokenMismatchException::class, |
21
|
|
|
\Illuminate\Validation\ValidationException::class, |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Report or log an exception. |
26
|
|
|
* |
27
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
28
|
|
|
* |
29
|
|
|
* @param \Exception $exception |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
5 |
|
public function report(Exception $exception) |
34
|
|
|
{ |
35
|
5 |
|
parent::report($exception); |
36
|
5 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Render an exception into an HTTP response. |
40
|
|
|
* |
41
|
|
|
* @param \Illuminate\Http\Request $request |
42
|
|
|
* @param \Exception $exception |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\Http\Response |
45
|
|
|
*/ |
46
|
5 |
|
public function render($request, Exception $exception) |
47
|
|
|
{ |
48
|
5 |
|
return parent::render($request, $exception); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Convert an authentication exception into an unauthenticated response. |
53
|
|
|
* |
54
|
|
|
* @param \Illuminate\Http\Request $request |
55
|
|
|
* |
56
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
57
|
|
|
*/ |
58
|
1 |
|
protected function unauthenticated($request) |
59
|
|
|
{ |
60
|
1 |
|
if ($request->expectsJson()) { |
61
|
|
|
return response()->json(['error' => 'Unauthenticated.'], 401); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
return redirect()->guest(route('login')); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|