1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* rmarchiv.tk |
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace App\Exceptions; |
9
|
|
|
|
10
|
|
|
use Exception; |
11
|
|
|
use Illuminate\Auth\AuthenticationException; |
12
|
|
|
use GrahamCampbell\Exceptions\ExceptionHandler; |
13
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
14
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
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
|
|
|
\Illuminate\Auth\AuthenticationException::class, |
25
|
|
|
\Illuminate\Auth\Access\AuthorizationException::class, |
26
|
|
|
\Symfony\Component\HttpKernel\Exception\HttpException::class, |
27
|
|
|
\Illuminate\Database\Eloquent\ModelNotFoundException::class, |
28
|
|
|
\Illuminate\Session\TokenMismatchException::class, |
29
|
|
|
\Illuminate\Validation\ValidationException::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Report or log an exception. |
34
|
|
|
* |
35
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
36
|
|
|
* |
37
|
|
|
* @param \Exception $exception |
38
|
|
|
* |
39
|
|
|
* @return void |
40
|
|
|
*/ |
41
|
|
|
public function report(Exception $exception) |
42
|
|
|
{ |
43
|
|
|
parent::report($exception); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Render an exception into an HTTP response. |
48
|
|
|
* |
49
|
|
|
* @param \Illuminate\Http\Request $request |
50
|
|
|
* @param \Exception $exception |
51
|
|
|
* |
52
|
|
|
* @return \Illuminate\Http\Response |
53
|
|
|
*/ |
54
|
|
|
public function render($request, Exception $exception) |
55
|
|
|
{ |
56
|
|
|
if ($exception instanceof NotFoundHttpException) { |
57
|
|
|
return response()->view('errors.404', [], 404); |
58
|
|
|
} elseif ($exception instanceof AccessDeniedHttpException) { |
59
|
|
|
return response()->view('errors.403', [], 403); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return parent::render($request, $exception); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Convert an authentication exception into an unauthenticated response. |
67
|
|
|
* |
68
|
|
|
* @param \Illuminate\Http\Request $request |
69
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
70
|
|
|
* |
71
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
72
|
|
|
*/ |
73
|
|
|
protected function unauthenticated($request, AuthenticationException $exception) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
if ($request->expectsJson()) { |
76
|
|
|
return response()->json(['error' => 'Unauthenticated.'], 401); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return redirect()->guest('login'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.