|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use App\Ajax\Web\Planning\Pool; |
|
6
|
|
|
use App\Ajax\Web\Planning\Round; |
|
7
|
|
|
use App\Ajax\Web\Tontine\Member; |
|
8
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
|
9
|
|
|
use Jaxon\Laravel\Jaxon; |
|
10
|
|
|
use Jaxon\Plugin\Request\CallableClass\CallableRegistry; |
|
11
|
|
|
use Siak\Tontine\Exception\AuthenticationException; |
|
12
|
|
|
use Siak\Tontine\Exception\MessageException; |
|
13
|
|
|
use Siak\Tontine\Exception\PlanningPoolException; |
|
14
|
|
|
use Siak\Tontine\Exception\PlanningRoundException; |
|
15
|
|
|
use Siak\Tontine\Exception\TontineMemberException; |
|
16
|
|
|
use Siak\Tontine\Service\TenantService; |
|
17
|
|
|
use Throwable; |
|
18
|
|
|
|
|
19
|
|
|
use function Jaxon\jaxon; |
|
20
|
|
|
use function app; |
|
21
|
|
|
use function route; |
|
22
|
|
|
use function trans; |
|
23
|
|
|
|
|
24
|
|
|
class Handler extends ExceptionHandler |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* A list of exception types with their corresponding custom log levels. |
|
28
|
|
|
* |
|
29
|
|
|
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*> |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
|
|
protected $levels = [ |
|
32
|
|
|
// |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* A list of the exception types that are not reported. |
|
37
|
|
|
* |
|
38
|
|
|
* @var array<int, class-string<\Throwable>> |
|
|
|
|
|
|
39
|
|
|
*/ |
|
40
|
|
|
protected $dontReport = [ |
|
41
|
|
|
AuthenticationException::class, |
|
42
|
|
|
MessageException::class, |
|
43
|
|
|
PlanningPoolException::class, |
|
44
|
|
|
PlanningRoundException::class, |
|
45
|
|
|
TontineMemberException::class, |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* A list of the inputs that are never flashed to the session on validation exceptions. |
|
50
|
|
|
* |
|
51
|
|
|
* @var array<int, string> |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $dontFlash = [ |
|
54
|
|
|
'current_password', |
|
55
|
|
|
'password', |
|
56
|
|
|
'password_confirmation', |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the instance of a callable class registered with Jaxon |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $class |
|
63
|
|
|
* |
|
64
|
|
|
* @return mixed |
|
65
|
|
|
*/ |
|
66
|
|
|
private function getCallableObject(string $class) |
|
67
|
|
|
{ |
|
68
|
|
|
// Todo: implement this feature in the Jaxon library. |
|
69
|
|
|
$registry = jaxon()->di()->g(CallableRegistry::class); |
|
70
|
|
|
$callable = $registry->getCallableObject($class)->getRegisteredObject(); |
|
71
|
|
|
|
|
72
|
|
|
$tenantService = app()->make(TenantService::class); |
|
73
|
|
|
return $callable->setTenantService($tenantService); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Register the exception handling callbacks for the application. |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
public function register() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->reportable(function (Throwable $e) { |
|
|
|
|
|
|
84
|
|
|
// |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
// Redirect to the login page |
|
88
|
|
|
$this->renderable(function (AuthenticationException $e) { |
|
|
|
|
|
|
89
|
|
|
$jaxon = app()->make(Jaxon::class); |
|
90
|
|
|
$ajaxResponse = $jaxon->ajaxResponse(); |
|
91
|
|
|
$ajaxResponse->redirect(route('login')); |
|
92
|
|
|
|
|
93
|
|
|
return $jaxon->httpResponse(); |
|
94
|
|
|
}); |
|
95
|
|
|
|
|
96
|
|
|
// Show the error message in a dialog |
|
97
|
|
|
$this->renderable(function (MessageException $e) { |
|
98
|
|
|
$jaxon = app()->make(Jaxon::class); |
|
99
|
|
|
$ajaxResponse = $jaxon->ajaxResponse(); |
|
100
|
|
|
$ajaxResponse->dialog->error($e->getMessage(), trans('common.titles.error')); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return $jaxon->httpResponse(); |
|
103
|
|
|
}); |
|
104
|
|
|
|
|
105
|
|
|
// Show the warning message in a dialog |
|
106
|
|
|
$this->renderable(function (PlanningRoundException $e) { |
|
107
|
|
|
$this->getCallableObject(Round::class)->home(); |
|
108
|
|
|
|
|
109
|
|
|
$jaxon = app()->make(Jaxon::class); |
|
110
|
|
|
$ajaxResponse = $jaxon->ajaxResponse(); |
|
111
|
|
|
$ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning')); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
return $jaxon->httpResponse(); |
|
114
|
|
|
}); |
|
115
|
|
|
|
|
116
|
|
|
// Show the warning message in a dialog |
|
117
|
|
|
$this->renderable(function (PlanningPoolException $e) { |
|
118
|
|
|
$this->getCallableObject(Pool::class)->home(); |
|
119
|
|
|
|
|
120
|
|
|
$jaxon = app()->make(Jaxon::class); |
|
121
|
|
|
$ajaxResponse = $jaxon->ajaxResponse(); |
|
122
|
|
|
$ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning')); |
|
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
return $jaxon->httpResponse(); |
|
125
|
|
|
}); |
|
126
|
|
|
|
|
127
|
|
|
// Show the warning message in a dialog |
|
128
|
|
|
$this->renderable(function (TontineMemberException $e) { |
|
129
|
|
|
$this->getCallableObject(Member::class)->home(); |
|
130
|
|
|
|
|
131
|
|
|
$jaxon = app()->make(Jaxon::class); |
|
132
|
|
|
$ajaxResponse = $jaxon->ajaxResponse(); |
|
133
|
|
|
$ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning')); |
|
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
return $jaxon->httpResponse(); |
|
136
|
|
|
}); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|