|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use Throwable; |
|
6
|
|
|
use Inertia\Inertia; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Illuminate\Support\Facades\Auth; |
|
9
|
|
|
use Illuminate\Support\Facades\Log; |
|
10
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
|
11
|
|
|
|
|
12
|
|
|
class Handler extends ExceptionHandler |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* A list of the exception types that are not reported. |
|
16
|
|
|
* |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $dontReport = [ |
|
20
|
|
|
// |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* A list of the inputs that are never flashed for validation exceptions. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $dontFlash = [ |
|
29
|
148 |
|
'current_password', |
|
30
|
|
|
'password', |
|
31
|
148 |
|
'password_confirmation', |
|
32
|
|
|
]; |
|
33
|
148 |
|
|
|
34
|
148 |
|
/** |
|
35
|
|
|
* Register the exception handling callbacks for the application. |
|
36
|
|
|
* |
|
37
|
|
|
* @return void |
|
38
|
|
|
*/ |
|
39
|
|
|
public function register() |
|
40
|
|
|
{ |
|
41
|
|
|
// $this->reportable(function (Throwable $e) { |
|
42
|
|
|
// // |
|
43
|
|
|
// }); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Check for an error message |
|
48
|
|
|
*/ |
|
49
|
|
|
public function render($request, Throwable $e) |
|
50
|
|
|
{ |
|
51
|
|
|
$response = parent::render($request, $e); |
|
52
|
|
|
|
|
53
|
|
|
if(!app()->environment(['local', 'testing']) && in_array($response->status(), [500, 503, 404, 403])) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
Log::notice('Server Error - '.$response->status().' occured. Message - '.$response->exception->getMessage(), [ |
|
56
|
|
|
'auth' => Auth::check() ? true : false, |
|
57
|
|
|
'user_id' => Auth::check() ? Auth::user()->user_id : null, |
|
58
|
|
|
'username' => Auth::check() ? Auth::user()->username : null, |
|
59
|
|
|
]); |
|
60
|
|
|
|
|
61
|
|
|
$message = $response->exception->getMessage(); |
|
62
|
|
|
|
|
63
|
|
|
if($message == "" || Str::startsWith($message, 'No query results')) |
|
64
|
|
|
{ |
|
65
|
|
|
$message = null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return Inertia::render('Error', [ |
|
69
|
|
|
'status' => $response->status(), |
|
70
|
|
|
'message' => $message, |
|
71
|
|
|
]) |
|
72
|
|
|
->toResponse($request) |
|
73
|
|
|
->setStatusCode($response->status()); |
|
74
|
|
|
} |
|
75
|
|
|
else if ($response->status() === 419) |
|
76
|
|
|
{ |
|
77
|
|
|
return back()->with([ |
|
78
|
|
|
'message' => 'The page expired, please try again.', |
|
79
|
|
|
'type' => 'danger', |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $response; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|