1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Auth\AuthenticationException; |
7
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
8
|
|
|
|
9
|
|
|
class Handler extends ExceptionHandler |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* A list of the exception types that should not be reported. |
13
|
|
|
* |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
protected $dontReport = [ |
17
|
|
|
\Illuminate\Auth\AuthenticationException::class, |
18
|
|
|
\Illuminate\Auth\Access\AuthorizationException::class, |
19
|
|
|
\Symfony\Component\HttpKernel\Exception\HttpException::class, |
20
|
|
|
\Illuminate\Database\Eloquent\ModelNotFoundException::class, |
21
|
|
|
\Illuminate\Session\TokenMismatchException::class, |
22
|
|
|
\Illuminate\Validation\ValidationException::class, |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Report or log an exception. |
27
|
|
|
* |
28
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
29
|
|
|
* |
30
|
|
|
* @param \Exception $exception |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function report(Exception $exception) |
34
|
|
|
{ |
35
|
|
|
parent::report($exception); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Render an exception into an HTTP response. |
40
|
|
|
* |
41
|
|
|
* @param \Illuminate\Http\Request $request |
42
|
|
|
* @param \Exception $exception |
43
|
|
|
* @return \Illuminate\Http\Response |
44
|
|
|
*/ |
45
|
|
|
public function render($request, Exception $exception) |
46
|
|
|
{ |
47
|
|
|
// Send a JSON 404 if using Api |
48
|
|
|
if ($exception instanceof ModelNotFoundException && $request->expectsJson()) { |
|
|
|
|
49
|
|
|
return response()->json([ |
|
|
|
|
50
|
|
|
'data' => 'Resource not found.' |
51
|
|
|
], 404); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return parent::render($request, $exception); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Convert an authentication exception into an unauthenticated response. |
59
|
|
|
* |
60
|
|
|
* @param \Illuminate\Http\Request $request |
61
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception |
62
|
|
|
* @return \Illuminate\Http\Response |
63
|
|
|
*/ |
64
|
|
|
protected function unauthenticated($request, AuthenticationException $exception) |
65
|
|
|
{ |
66
|
|
|
if ($request->expectsJson()) { |
67
|
|
|
return response()->json([ |
|
|
|
|
68
|
|
|
'error' => 'Unauthenticated.' |
69
|
|
|
], 401); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return redirect()->guest(route('login')); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths