1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Faecie\Bundle\JsonApiErrorResponseBundle\ExceptionDescriber; |
6
|
|
|
|
7
|
|
|
use Faecie\Bundle\JsonApiErrorResponseBundle\Enum\ErrorCodesEnum; |
8
|
|
|
use Faecie\Bundle\JsonApiErrorResponseBundle\JsonApi\Error; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
11
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
12
|
|
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException; |
13
|
|
|
use Symfony\Component\Security\Core\Exception\AccountExpiredException; |
14
|
|
|
use Symfony\Component\Security\Core\Exception\AccountStatusException; |
15
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException; |
16
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
17
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationExpiredException; |
18
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException; |
19
|
|
|
use Symfony\Component\Security\Core\Exception\BadCredentialsException; |
20
|
|
|
use Symfony\Component\Security\Core\Exception\CookieTheftException; |
21
|
|
|
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException; |
22
|
|
|
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException; |
23
|
|
|
use Symfony\Component\Security\Core\Exception\DisabledException; |
24
|
|
|
use Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException; |
25
|
|
|
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException; |
26
|
|
|
use Symfony\Component\Security\Core\Exception\LockedException; |
27
|
|
|
use Symfony\Component\Security\Core\Exception\ProviderNotFoundException; |
28
|
|
|
use Symfony\Component\Security\Core\Exception\SessionUnavailableException; |
29
|
|
|
use Symfony\Component\Security\Core\Exception\TokenNotFoundException; |
30
|
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
31
|
|
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
32
|
|
|
|
33
|
|
|
class SymfonyExceptionDescriber extends PreconfiguredExceptionsDescriber |
34
|
|
|
{ |
35
|
3 |
|
public function __construct() |
36
|
|
|
{ |
37
|
3 |
|
parent::__construct( |
38
|
|
|
[ |
39
|
|
|
NotFoundHttpException::class => |
40
|
3 |
|
new Error( |
41
|
3 |
|
ErrorCodesEnum::RESOURCE_NOT_FOUND, |
42
|
3 |
|
null, |
43
|
3 |
|
null, |
44
|
3 |
|
Response::HTTP_NOT_FOUND |
45
|
|
|
), |
46
|
|
|
MethodNotAllowedException::class => |
47
|
3 |
|
new Error( |
48
|
3 |
|
ErrorCodesEnum::RESOURCE_METHOD_NOT_ALLOWED, |
49
|
3 |
|
null, |
50
|
3 |
|
null, |
51
|
3 |
|
Response::HTTP_METHOD_NOT_ALLOWED |
52
|
|
|
), |
53
|
|
|
BadRequestHttpException::class => |
54
|
3 |
|
new Error( |
55
|
3 |
|
ErrorCodesEnum::VALIDATION, |
56
|
3 |
|
null, |
57
|
3 |
|
null, |
58
|
3 |
|
Response::HTTP_BAD_REQUEST |
59
|
|
|
), |
60
|
|
|
AuthenticationCredentialsNotFoundException::class => |
61
|
3 |
|
new Error( |
62
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_NOT_FOUND, |
63
|
3 |
|
null, |
64
|
3 |
|
null, |
65
|
3 |
|
Response::HTTP_UNAUTHORIZED |
66
|
|
|
), |
67
|
|
|
BadCredentialsException::class => |
68
|
3 |
|
new Error( |
69
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_BAD_CREDENTIALS, |
70
|
3 |
|
null, |
71
|
3 |
|
null, |
72
|
3 |
|
Response::HTTP_BAD_REQUEST |
73
|
|
|
), |
74
|
|
|
AuthenticationServiceException::class => |
75
|
3 |
|
new Error( |
76
|
3 |
|
ErrorCodesEnum::TEMPORARY_UNAVAILABLE, |
77
|
3 |
|
null, |
78
|
3 |
|
null, |
79
|
3 |
|
Response::HTTP_SERVICE_UNAVAILABLE |
80
|
|
|
), |
81
|
|
|
DisabledException::class => |
82
|
3 |
|
new Error( |
83
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_ACCESS_FORBIDDEN, |
84
|
3 |
|
null, |
85
|
3 |
|
null, |
86
|
3 |
|
Response::HTTP_FORBIDDEN |
87
|
|
|
), |
88
|
|
|
CredentialsExpiredException::class => |
89
|
3 |
|
new Error( |
90
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_EXPIRED, |
91
|
3 |
|
null, |
92
|
3 |
|
null, |
93
|
3 |
|
Response::HTTP_UNAUTHORIZED |
94
|
|
|
), |
95
|
|
|
AccountExpiredException::class => |
96
|
3 |
|
new Error( |
97
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_EXPIRED, |
98
|
3 |
|
null, |
99
|
3 |
|
null, |
100
|
3 |
|
Response::HTTP_UNAUTHORIZED |
101
|
|
|
), |
102
|
|
|
AuthenticationExpiredException::class => |
103
|
3 |
|
new Error( |
104
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_EXPIRED, |
105
|
3 |
|
null, |
106
|
3 |
|
null, |
107
|
3 |
|
Response::HTTP_UNAUTHORIZED |
108
|
|
|
), |
109
|
|
|
InvalidCsrfTokenException::class => |
110
|
3 |
|
new Error( |
111
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_ACCESS_FORBIDDEN, |
112
|
3 |
|
null, |
113
|
3 |
|
null, |
114
|
3 |
|
Response::HTTP_FORBIDDEN |
115
|
|
|
), |
116
|
|
|
UsernameNotFoundException::class => |
117
|
3 |
|
new Error( |
118
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_BAD_CREDENTIALS, |
119
|
3 |
|
null, |
120
|
3 |
|
null, |
121
|
3 |
|
Response::HTTP_BAD_REQUEST |
122
|
|
|
), |
123
|
|
|
UnsupportedUserException::class => |
124
|
3 |
|
new Error( |
125
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_BAD_CREDENTIALS, |
126
|
3 |
|
null, |
127
|
3 |
|
null, |
128
|
3 |
|
Response::HTTP_BAD_REQUEST |
129
|
|
|
), |
130
|
|
|
SessionUnavailableException::class => |
131
|
3 |
|
new Error( |
132
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_BAD_CREDENTIALS, |
133
|
3 |
|
null, |
134
|
3 |
|
null, |
135
|
3 |
|
Response::HTTP_BAD_REQUEST |
136
|
|
|
), |
137
|
|
|
CustomUserMessageAuthenticationException::class => |
138
|
3 |
|
new Error( |
139
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_BAD_CREDENTIALS, |
140
|
3 |
|
null, |
141
|
3 |
|
null, |
142
|
3 |
|
Response::HTTP_UNAUTHORIZED |
143
|
|
|
), |
144
|
|
|
ProviderNotFoundException::class => |
145
|
3 |
|
new Error( |
146
|
3 |
|
ErrorCodesEnum::INTERNAL, |
147
|
3 |
|
null, |
148
|
3 |
|
null, |
149
|
3 |
|
Response::HTTP_INTERNAL_SERVER_ERROR |
150
|
|
|
), |
151
|
|
|
TokenNotFoundException::class => |
152
|
3 |
|
new Error( |
153
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_NOT_FOUND, |
154
|
3 |
|
null, |
155
|
3 |
|
null, |
156
|
3 |
|
Response::HTTP_FORBIDDEN |
157
|
|
|
), |
158
|
|
|
CookieTheftException::class => |
159
|
3 |
|
new Error( |
160
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_NOT_FOUND, |
161
|
3 |
|
null, |
162
|
3 |
|
null, |
163
|
3 |
|
Response::HTTP_UNAUTHORIZED |
164
|
|
|
), |
165
|
|
|
InsufficientAuthenticationException::class => |
166
|
3 |
|
new Error( |
167
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_BAD_CREDENTIALS, |
168
|
3 |
|
null, |
169
|
3 |
|
null, |
170
|
3 |
|
Response::HTTP_BAD_REQUEST |
171
|
|
|
), |
172
|
|
|
LockedException::class => |
173
|
3 |
|
new Error( |
174
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_ACCESS_FORBIDDEN, |
175
|
3 |
|
null, |
176
|
3 |
|
null, |
177
|
3 |
|
Response::HTTP_FORBIDDEN |
178
|
|
|
), |
179
|
|
|
AccountStatusException::class => |
180
|
3 |
|
new Error( |
181
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_ACCESS_FORBIDDEN, |
182
|
3 |
|
null, |
183
|
3 |
|
null, |
184
|
3 |
|
Response::HTTP_FORBIDDEN |
185
|
|
|
), |
186
|
|
|
AuthenticationException::class => |
187
|
3 |
|
new Error( |
188
|
3 |
|
ErrorCodesEnum::AUTHORIZATION_CREDENTIALS_NOT_FOUND, |
189
|
3 |
|
null, |
190
|
3 |
|
null, |
191
|
3 |
|
Response::HTTP_UNAUTHORIZED |
192
|
|
|
), |
193
|
|
|
] |
194
|
|
|
); |
195
|
3 |
|
} |
196
|
|
|
} |
197
|
|
|
|