@@ -27,180 +27,180 @@ |
||
27 | 27 | */ |
28 | 28 | class ExceptionHandlerHelper |
29 | 29 | { |
30 | - /** |
|
31 | - * Render an exception into valid API response. |
|
32 | - * |
|
33 | - * @param \Illuminate\Http\Request $request Request object |
|
34 | - * @param \Exception $ex Exception |
|
35 | - * |
|
36 | - * @return HttpResponse |
|
37 | - */ |
|
38 | - public static function render(/** @scrutinizer ignore-unused */ $request, Exception $ex): HttpResponse |
|
39 | - { |
|
40 | - $result = null; |
|
41 | - $cfg = self::getExceptionHandlerConfig(); |
|
42 | - |
|
43 | - if ($ex instanceof HttpException) { |
|
44 | - // Check if we have any exception configuration for this particular Http status code. |
|
45 | - $ex_cfg = $cfg[ HttpException::class ][ $ex->getStatusCode() ] ?? null; |
|
46 | - if ($ex_cfg === null) { |
|
47 | - $ex_cfg = $cfg[ HttpException::class ]['default']; |
|
48 | - } |
|
49 | - |
|
50 | - $api_code = $ex_cfg['api_code'] ?? BaseApiCodes::EX_UNCAUGHT_EXCEPTION(); |
|
51 | - $http_code = $ex_cfg['http_code'] ?? ResponseBuilder::DEFAULT_HTTP_CODE_ERROR; |
|
52 | - $msg_key = $ex_cfg['msg_key'] ?? null; |
|
53 | - $result = static::error($ex, $api_code, $http_code, $msg_key); |
|
54 | - } elseif ($ex instanceof ValidationException) { |
|
55 | - $http_code = HttpResponse::HTTP_UNPROCESSABLE_ENTITY; |
|
56 | - $ex_cfg = $cfg[ HttpException::class ][ $http_code ]; |
|
57 | - $api_code = $ex_cfg['api_code'] ?? BaseApiCodes::EX_UNCAUGHT_EXCEPTION(); |
|
58 | - $http_code = $ex_cfg['http_code'] ?? $http_code; |
|
59 | - $result = static::error($ex, $api_code, $http_code); |
|
60 | - } |
|
61 | - |
|
62 | - if ($result === null) { |
|
63 | - $ex_cfg = $cfg['default']; |
|
64 | - $result = static::error($ex, $ex_cfg['api_code'], $ex_cfg['http_code']); |
|
65 | - } |
|
66 | - |
|
67 | - return $result; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Convert an authentication exception into an unauthenticated response. |
|
72 | - * |
|
73 | - * @param \Illuminate\Http\Request $request |
|
74 | - * @param \Illuminate\Auth\AuthenticationException $exception |
|
75 | - * |
|
76 | - * @return HttpResponse |
|
77 | - */ |
|
78 | - protected function unauthenticated(/** @scrutinizer ignore-unused */ $request, |
|
79 | - AuthException $exception): HttpResponse |
|
80 | - { |
|
81 | - $cfg = static::getExceptionHandlerConfig(HttpException::class); |
|
82 | - $api_code = $cfg[ HttpResponse::HTTP_UNAUTHORIZED ]['api_code']; |
|
83 | - $http_code = $cfg[ HttpResponse::HTTP_UNAUTHORIZED ]['http_code']; |
|
84 | - |
|
85 | - return static::error($exception, $api_code, $http_code); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Process single error and produce valid API response. |
|
90 | - * |
|
91 | - * @param Exception $ex Exception to be handled. |
|
92 | - * @param integer $api_code |
|
93 | - * @param integer $http_code |
|
94 | - * |
|
95 | - * @return HttpResponse |
|
96 | - */ |
|
97 | - protected static function error(Exception $ex, |
|
98 | - int $api_code, int $http_code = null, string $msg_key = null): HttpResponse |
|
99 | - { |
|
100 | - $ex_http_code = ($ex instanceof HttpException) ? $ex->getStatusCode() : $ex->getCode(); |
|
101 | - $http_code = $http_code ?? $ex_http_code; |
|
102 | - |
|
103 | - // Check if we now have valid HTTP error code for this case or need to make one up. |
|
104 | - // We cannot throw any exception if codes are invalid because we are in Exception Handler already. |
|
105 | - if ($http_code < ResponseBuilder::ERROR_HTTP_CODE_MIN) { |
|
106 | - // Not a valid code, let's try to get the exception status. |
|
107 | - $http_code = $ex_http_code; |
|
108 | - } |
|
109 | - // Can it be considered a valid HTTP error code? |
|
110 | - if ($http_code < ResponseBuilder::ERROR_HTTP_CODE_MIN) { |
|
111 | - $http_code = ResponseBuilder::DEFAULT_HTTP_CODE_ERROR; |
|
112 | - } |
|
113 | - |
|
114 | - // Let's build the error message. |
|
115 | - $error_message = $ex->getMessage(); |
|
116 | - |
|
117 | - $placeholders = [ |
|
118 | - 'api_code' => $api_code, |
|
119 | - 'message' => ($error_message !== '') ? $error_message : '???', |
|
120 | - ]; |
|
121 | - |
|
122 | - // Check if we have dedicated HTTP Code message for this type of HttpException and its status code. |
|
123 | - if (($error_message === '') && ($ex instanceof HttpException)) { |
|
124 | - $error_message = Lang::get("response-builder::builder.http_{$ex_http_code}", $placeholders); |
|
125 | - } |
|
126 | - |
|
127 | - // Still got nothing? Fall back to built-in generic message for this type of exception. |
|
128 | - if ($error_message === '') { |
|
129 | - $key = BaseApiCodes::getCodeMessageKey(($ex instanceof HttpException) |
|
130 | - ? BaseApiCodes::EX_HTTP_EXCEPTION() : BaseApiCodes::NO_ERROR_MESSAGE()); |
|
131 | - $error_message = Lang::get($key, $placeholders); |
|
132 | - } |
|
133 | - |
|
134 | - // If we have trace data debugging enabled, let's gather some debug info and add to the response. |
|
135 | - $trace_data = null; |
|
136 | - if (Config::get(ResponseBuilder::CONF_KEY_DEBUG_EX_TRACE_ENABLED, false)) { |
|
137 | - $trace_data = [ |
|
138 | - Config::get(ResponseBuilder::CONF_KEY_DEBUG_EX_TRACE_KEY, ResponseBuilder::KEY_TRACE) => [ |
|
139 | - ResponseBuilder::KEY_CLASS => get_class($ex), |
|
140 | - ResponseBuilder::KEY_FILE => $ex->getFile(), |
|
141 | - ResponseBuilder::KEY_LINE => $ex->getLine(), |
|
142 | - ], |
|
143 | - ]; |
|
144 | - } |
|
145 | - |
|
146 | - // If this is ValidationException, add all the messages from MessageBag to the data node. |
|
147 | - $data = null; |
|
148 | - if ($ex instanceof ValidationException) { |
|
149 | - /** @var ValidationException $ex */ |
|
150 | - $data = [ResponseBuilder::KEY_MESSAGES => $ex->validator->errors()->messages()]; |
|
151 | - } |
|
152 | - |
|
153 | - return ResponseBuilder::errorWithMessageAndDataAndDebug($api_code, $error_message, $data, |
|
154 | - $http_code, null, $trace_data); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns built-in configration array for ExceptionHandlerHelper |
|
159 | - * |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - protected static function getExceptionHandlerBaseConfig(): array |
|
163 | - { |
|
164 | - return [ |
|
165 | - HttpException::class => [ |
|
166 | - // used by unauthenticated() to obtain api and http code for the exception |
|
167 | - HttpResponse::HTTP_UNAUTHORIZED => [ |
|
168 | - 'api_code' => BaseApiCodes::EX_AUTHENTICATION_EXCEPTION(), |
|
169 | - 'http_code' => HttpResponse::HTTP_UNAUTHORIZED, |
|
170 | - ], |
|
171 | - |
|
172 | - // Required by ValidationException handler |
|
173 | - HttpResponse::HTTP_UNPROCESSABLE_ENTITY => [ |
|
174 | - 'api_code' => BaseApiCodes::EX_VALIDATION_EXCEPTION(), |
|
175 | - 'http_code' => HttpResponse::HTTP_UNPROCESSABLE_ENTITY, |
|
176 | - ], |
|
177 | - // default handler is mandatory |
|
178 | - 'default' => [ |
|
179 | - 'api_code' => BaseApiCodes::EX_HTTP_EXCEPTION(), |
|
180 | - 'http_code' => HttpResponse::HTTP_BAD_REQUEST, |
|
181 | - ], |
|
182 | - ], |
|
183 | - // default handler is mandatory |
|
184 | - 'default' => [ |
|
185 | - 'api_code' => BaseApiCodes::EX_UNCAUGHT_EXCEPTION(), |
|
186 | - 'http_code' => HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
|
187 | - ], |
|
188 | - ]; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Returns configration array for ExceptionHandlerHelper with user config merged with built-in config. |
|
193 | - * |
|
194 | - * @param string|null $key optional configuration node key to have only this portion of the |
|
195 | - * config returned (i.e. `http_exception`). |
|
196 | - * |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - protected static function getExceptionHandlerConfig(string $key = null): array |
|
200 | - { |
|
201 | - $result = array_merge(Config::get(ResponseBuilder::CONF_EXCEPTION_HANDLER_KEY, []), |
|
202 | - self::getExceptionHandlerBaseConfig()); |
|
203 | - |
|
204 | - return ($key === null) ? $result : $result[ $key ]; |
|
205 | - } |
|
30 | + /** |
|
31 | + * Render an exception into valid API response. |
|
32 | + * |
|
33 | + * @param \Illuminate\Http\Request $request Request object |
|
34 | + * @param \Exception $ex Exception |
|
35 | + * |
|
36 | + * @return HttpResponse |
|
37 | + */ |
|
38 | + public static function render(/** @scrutinizer ignore-unused */ $request, Exception $ex): HttpResponse |
|
39 | + { |
|
40 | + $result = null; |
|
41 | + $cfg = self::getExceptionHandlerConfig(); |
|
42 | + |
|
43 | + if ($ex instanceof HttpException) { |
|
44 | + // Check if we have any exception configuration for this particular Http status code. |
|
45 | + $ex_cfg = $cfg[ HttpException::class ][ $ex->getStatusCode() ] ?? null; |
|
46 | + if ($ex_cfg === null) { |
|
47 | + $ex_cfg = $cfg[ HttpException::class ]['default']; |
|
48 | + } |
|
49 | + |
|
50 | + $api_code = $ex_cfg['api_code'] ?? BaseApiCodes::EX_UNCAUGHT_EXCEPTION(); |
|
51 | + $http_code = $ex_cfg['http_code'] ?? ResponseBuilder::DEFAULT_HTTP_CODE_ERROR; |
|
52 | + $msg_key = $ex_cfg['msg_key'] ?? null; |
|
53 | + $result = static::error($ex, $api_code, $http_code, $msg_key); |
|
54 | + } elseif ($ex instanceof ValidationException) { |
|
55 | + $http_code = HttpResponse::HTTP_UNPROCESSABLE_ENTITY; |
|
56 | + $ex_cfg = $cfg[ HttpException::class ][ $http_code ]; |
|
57 | + $api_code = $ex_cfg['api_code'] ?? BaseApiCodes::EX_UNCAUGHT_EXCEPTION(); |
|
58 | + $http_code = $ex_cfg['http_code'] ?? $http_code; |
|
59 | + $result = static::error($ex, $api_code, $http_code); |
|
60 | + } |
|
61 | + |
|
62 | + if ($result === null) { |
|
63 | + $ex_cfg = $cfg['default']; |
|
64 | + $result = static::error($ex, $ex_cfg['api_code'], $ex_cfg['http_code']); |
|
65 | + } |
|
66 | + |
|
67 | + return $result; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Convert an authentication exception into an unauthenticated response. |
|
72 | + * |
|
73 | + * @param \Illuminate\Http\Request $request |
|
74 | + * @param \Illuminate\Auth\AuthenticationException $exception |
|
75 | + * |
|
76 | + * @return HttpResponse |
|
77 | + */ |
|
78 | + protected function unauthenticated(/** @scrutinizer ignore-unused */ $request, |
|
79 | + AuthException $exception): HttpResponse |
|
80 | + { |
|
81 | + $cfg = static::getExceptionHandlerConfig(HttpException::class); |
|
82 | + $api_code = $cfg[ HttpResponse::HTTP_UNAUTHORIZED ]['api_code']; |
|
83 | + $http_code = $cfg[ HttpResponse::HTTP_UNAUTHORIZED ]['http_code']; |
|
84 | + |
|
85 | + return static::error($exception, $api_code, $http_code); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Process single error and produce valid API response. |
|
90 | + * |
|
91 | + * @param Exception $ex Exception to be handled. |
|
92 | + * @param integer $api_code |
|
93 | + * @param integer $http_code |
|
94 | + * |
|
95 | + * @return HttpResponse |
|
96 | + */ |
|
97 | + protected static function error(Exception $ex, |
|
98 | + int $api_code, int $http_code = null, string $msg_key = null): HttpResponse |
|
99 | + { |
|
100 | + $ex_http_code = ($ex instanceof HttpException) ? $ex->getStatusCode() : $ex->getCode(); |
|
101 | + $http_code = $http_code ?? $ex_http_code; |
|
102 | + |
|
103 | + // Check if we now have valid HTTP error code for this case or need to make one up. |
|
104 | + // We cannot throw any exception if codes are invalid because we are in Exception Handler already. |
|
105 | + if ($http_code < ResponseBuilder::ERROR_HTTP_CODE_MIN) { |
|
106 | + // Not a valid code, let's try to get the exception status. |
|
107 | + $http_code = $ex_http_code; |
|
108 | + } |
|
109 | + // Can it be considered a valid HTTP error code? |
|
110 | + if ($http_code < ResponseBuilder::ERROR_HTTP_CODE_MIN) { |
|
111 | + $http_code = ResponseBuilder::DEFAULT_HTTP_CODE_ERROR; |
|
112 | + } |
|
113 | + |
|
114 | + // Let's build the error message. |
|
115 | + $error_message = $ex->getMessage(); |
|
116 | + |
|
117 | + $placeholders = [ |
|
118 | + 'api_code' => $api_code, |
|
119 | + 'message' => ($error_message !== '') ? $error_message : '???', |
|
120 | + ]; |
|
121 | + |
|
122 | + // Check if we have dedicated HTTP Code message for this type of HttpException and its status code. |
|
123 | + if (($error_message === '') && ($ex instanceof HttpException)) { |
|
124 | + $error_message = Lang::get("response-builder::builder.http_{$ex_http_code}", $placeholders); |
|
125 | + } |
|
126 | + |
|
127 | + // Still got nothing? Fall back to built-in generic message for this type of exception. |
|
128 | + if ($error_message === '') { |
|
129 | + $key = BaseApiCodes::getCodeMessageKey(($ex instanceof HttpException) |
|
130 | + ? BaseApiCodes::EX_HTTP_EXCEPTION() : BaseApiCodes::NO_ERROR_MESSAGE()); |
|
131 | + $error_message = Lang::get($key, $placeholders); |
|
132 | + } |
|
133 | + |
|
134 | + // If we have trace data debugging enabled, let's gather some debug info and add to the response. |
|
135 | + $trace_data = null; |
|
136 | + if (Config::get(ResponseBuilder::CONF_KEY_DEBUG_EX_TRACE_ENABLED, false)) { |
|
137 | + $trace_data = [ |
|
138 | + Config::get(ResponseBuilder::CONF_KEY_DEBUG_EX_TRACE_KEY, ResponseBuilder::KEY_TRACE) => [ |
|
139 | + ResponseBuilder::KEY_CLASS => get_class($ex), |
|
140 | + ResponseBuilder::KEY_FILE => $ex->getFile(), |
|
141 | + ResponseBuilder::KEY_LINE => $ex->getLine(), |
|
142 | + ], |
|
143 | + ]; |
|
144 | + } |
|
145 | + |
|
146 | + // If this is ValidationException, add all the messages from MessageBag to the data node. |
|
147 | + $data = null; |
|
148 | + if ($ex instanceof ValidationException) { |
|
149 | + /** @var ValidationException $ex */ |
|
150 | + $data = [ResponseBuilder::KEY_MESSAGES => $ex->validator->errors()->messages()]; |
|
151 | + } |
|
152 | + |
|
153 | + return ResponseBuilder::errorWithMessageAndDataAndDebug($api_code, $error_message, $data, |
|
154 | + $http_code, null, $trace_data); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns built-in configration array for ExceptionHandlerHelper |
|
159 | + * |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + protected static function getExceptionHandlerBaseConfig(): array |
|
163 | + { |
|
164 | + return [ |
|
165 | + HttpException::class => [ |
|
166 | + // used by unauthenticated() to obtain api and http code for the exception |
|
167 | + HttpResponse::HTTP_UNAUTHORIZED => [ |
|
168 | + 'api_code' => BaseApiCodes::EX_AUTHENTICATION_EXCEPTION(), |
|
169 | + 'http_code' => HttpResponse::HTTP_UNAUTHORIZED, |
|
170 | + ], |
|
171 | + |
|
172 | + // Required by ValidationException handler |
|
173 | + HttpResponse::HTTP_UNPROCESSABLE_ENTITY => [ |
|
174 | + 'api_code' => BaseApiCodes::EX_VALIDATION_EXCEPTION(), |
|
175 | + 'http_code' => HttpResponse::HTTP_UNPROCESSABLE_ENTITY, |
|
176 | + ], |
|
177 | + // default handler is mandatory |
|
178 | + 'default' => [ |
|
179 | + 'api_code' => BaseApiCodes::EX_HTTP_EXCEPTION(), |
|
180 | + 'http_code' => HttpResponse::HTTP_BAD_REQUEST, |
|
181 | + ], |
|
182 | + ], |
|
183 | + // default handler is mandatory |
|
184 | + 'default' => [ |
|
185 | + 'api_code' => BaseApiCodes::EX_UNCAUGHT_EXCEPTION(), |
|
186 | + 'http_code' => HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
|
187 | + ], |
|
188 | + ]; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Returns configration array for ExceptionHandlerHelper with user config merged with built-in config. |
|
193 | + * |
|
194 | + * @param string|null $key optional configuration node key to have only this portion of the |
|
195 | + * config returned (i.e. `http_exception`). |
|
196 | + * |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + protected static function getExceptionHandlerConfig(string $key = null): array |
|
200 | + { |
|
201 | + $result = array_merge(Config::get(ResponseBuilder::CONF_EXCEPTION_HANDLER_KEY, []), |
|
202 | + self::getExceptionHandlerBaseConfig()); |
|
203 | + |
|
204 | + return ($key === null) ? $result : $result[ $key ]; |
|
205 | + } |
|
206 | 206 | } |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | |
43 | 43 | if ($ex instanceof HttpException) { |
44 | 44 | // Check if we have any exception configuration for this particular Http status code. |
45 | - $ex_cfg = $cfg[ HttpException::class ][ $ex->getStatusCode() ] ?? null; |
|
45 | + $ex_cfg = $cfg[HttpException::class][$ex->getStatusCode()] ?? null; |
|
46 | 46 | if ($ex_cfg === null) { |
47 | - $ex_cfg = $cfg[ HttpException::class ]['default']; |
|
47 | + $ex_cfg = $cfg[HttpException::class]['default']; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $api_code = $ex_cfg['api_code'] ?? BaseApiCodes::EX_UNCAUGHT_EXCEPTION(); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $result = static::error($ex, $api_code, $http_code, $msg_key); |
54 | 54 | } elseif ($ex instanceof ValidationException) { |
55 | 55 | $http_code = HttpResponse::HTTP_UNPROCESSABLE_ENTITY; |
56 | - $ex_cfg = $cfg[ HttpException::class ][ $http_code ]; |
|
56 | + $ex_cfg = $cfg[HttpException::class][$http_code]; |
|
57 | 57 | $api_code = $ex_cfg['api_code'] ?? BaseApiCodes::EX_UNCAUGHT_EXCEPTION(); |
58 | 58 | $http_code = $ex_cfg['http_code'] ?? $http_code; |
59 | 59 | $result = static::error($ex, $api_code, $http_code); |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | AuthException $exception): HttpResponse |
80 | 80 | { |
81 | 81 | $cfg = static::getExceptionHandlerConfig(HttpException::class); |
82 | - $api_code = $cfg[ HttpResponse::HTTP_UNAUTHORIZED ]['api_code']; |
|
83 | - $http_code = $cfg[ HttpResponse::HTTP_UNAUTHORIZED ]['http_code']; |
|
82 | + $api_code = $cfg[HttpResponse::HTTP_UNAUTHORIZED]['api_code']; |
|
83 | + $http_code = $cfg[HttpResponse::HTTP_UNAUTHORIZED]['http_code']; |
|
84 | 84 | |
85 | 85 | return static::error($exception, $api_code, $http_code); |
86 | 86 | } |
@@ -201,6 +201,6 @@ discard block |
||
201 | 201 | $result = array_merge(Config::get(ResponseBuilder::CONF_EXCEPTION_HANDLER_KEY, []), |
202 | 202 | self::getExceptionHandlerBaseConfig()); |
203 | 203 | |
204 | - return ($key === null) ? $result : $result[ $key ]; |
|
204 | + return ($key === null) ? $result : $result[$key]; |
|
205 | 205 | } |
206 | 206 | } |
@@ -10,54 +10,54 @@ |
||
10 | 10 | */ |
11 | 11 | return [ |
12 | 12 | |
13 | - 'ok' => 'OK', |
|
14 | - 'no_error_message' => 'Błąd #:api_code', |
|
13 | + 'ok' => 'OK', |
|
14 | + 'no_error_message' => 'Błąd #:api_code', |
|
15 | 15 | |
16 | - // Used by Exception Handler Helper (when used) |
|
17 | - 'uncaught_exception' => 'Nieprzechwycony wyjątek: :message', |
|
18 | - 'http_exception' => 'Wyjątek HTTP: :message', |
|
16 | + // Used by Exception Handler Helper (when used) |
|
17 | + 'uncaught_exception' => 'Nieprzechwycony wyjątek: :message', |
|
18 | + 'http_exception' => 'Wyjątek HTTP: :message', |
|
19 | 19 | |
20 | - // HttpException handler (added in 6.4.0) |
|
21 | - // Error messages for HttpException caught w/o custom messages |
|
22 | - // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
23 | - 'http_400' => 'Bad Request', |
|
24 | - 'http_401' => 'Unauthorized', |
|
25 | - 'http_402' => 'Payment Required', |
|
26 | - 'http_403' => 'Forbidden', |
|
27 | - 'http_404' => 'Not Found', |
|
28 | - 'http_405' => 'Method Not Allowed', |
|
29 | - 'http_406' => 'Not Acceptable', |
|
30 | - 'http_407' => 'Proxy Authentication Required', |
|
31 | - 'http_408' => 'Request Timeout', |
|
32 | - 'http_409' => 'Conflict', |
|
33 | - 'http_410' => 'Gone', |
|
34 | - 'http_411' => 'Length Required', |
|
35 | - 'http_412' => 'Precondition Failed', |
|
36 | - 'http_413' => 'Payload Too Large', |
|
37 | - 'http_414' => 'URI Too Long', |
|
38 | - 'http_415' => 'Unsupported Media Type', |
|
39 | - 'http_416' => 'Range Not Satisfiable', |
|
40 | - 'http_417' => 'Expectation Failed', |
|
41 | - 'http_421' => 'Misdirected Request', |
|
42 | - 'http_422' => 'Unprocessable Entity', |
|
43 | - 'http_423' => 'Locked', |
|
44 | - 'http_424' => 'Failed Dependency', |
|
45 | - 'http_425' => 'Too Early', |
|
46 | - 'http_426' => 'Upgrade Required', |
|
47 | - 'http_428' => 'Precondition Required', |
|
48 | - 'http_429' => 'Too Many Requests', |
|
49 | - 'http_431' => 'Request Header Fields Too Large', |
|
50 | - 'http_451' => 'Unavailable For Legal Reasons', |
|
51 | - 'http_500' => 'Internal Server Error', |
|
52 | - 'http_501' => 'Not Implemented', |
|
53 | - 'http_502' => 'Bad Gateway', |
|
54 | - 'http_503' => 'Service Unavailable', |
|
55 | - 'http_504' => 'Gateway Timeout', |
|
56 | - 'http_505' => 'HTTP Version Not Supported', |
|
57 | - 'http_506' => 'Variant Also Negotiates', |
|
58 | - 'http_507' => 'Insufficient Storage', |
|
59 | - 'http_508' => 'Loop Detected', |
|
60 | - 'http_509' => 'Unassigned', |
|
61 | - 'http_510' => 'Not Extended', |
|
62 | - 'http_511' => 'Network Authentication Required', |
|
20 | + // HttpException handler (added in 6.4.0) |
|
21 | + // Error messages for HttpException caught w/o custom messages |
|
22 | + // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
23 | + 'http_400' => 'Bad Request', |
|
24 | + 'http_401' => 'Unauthorized', |
|
25 | + 'http_402' => 'Payment Required', |
|
26 | + 'http_403' => 'Forbidden', |
|
27 | + 'http_404' => 'Not Found', |
|
28 | + 'http_405' => 'Method Not Allowed', |
|
29 | + 'http_406' => 'Not Acceptable', |
|
30 | + 'http_407' => 'Proxy Authentication Required', |
|
31 | + 'http_408' => 'Request Timeout', |
|
32 | + 'http_409' => 'Conflict', |
|
33 | + 'http_410' => 'Gone', |
|
34 | + 'http_411' => 'Length Required', |
|
35 | + 'http_412' => 'Precondition Failed', |
|
36 | + 'http_413' => 'Payload Too Large', |
|
37 | + 'http_414' => 'URI Too Long', |
|
38 | + 'http_415' => 'Unsupported Media Type', |
|
39 | + 'http_416' => 'Range Not Satisfiable', |
|
40 | + 'http_417' => 'Expectation Failed', |
|
41 | + 'http_421' => 'Misdirected Request', |
|
42 | + 'http_422' => 'Unprocessable Entity', |
|
43 | + 'http_423' => 'Locked', |
|
44 | + 'http_424' => 'Failed Dependency', |
|
45 | + 'http_425' => 'Too Early', |
|
46 | + 'http_426' => 'Upgrade Required', |
|
47 | + 'http_428' => 'Precondition Required', |
|
48 | + 'http_429' => 'Too Many Requests', |
|
49 | + 'http_431' => 'Request Header Fields Too Large', |
|
50 | + 'http_451' => 'Unavailable For Legal Reasons', |
|
51 | + 'http_500' => 'Internal Server Error', |
|
52 | + 'http_501' => 'Not Implemented', |
|
53 | + 'http_502' => 'Bad Gateway', |
|
54 | + 'http_503' => 'Service Unavailable', |
|
55 | + 'http_504' => 'Gateway Timeout', |
|
56 | + 'http_505' => 'HTTP Version Not Supported', |
|
57 | + 'http_506' => 'Variant Also Negotiates', |
|
58 | + 'http_507' => 'Insufficient Storage', |
|
59 | + 'http_508' => 'Loop Detected', |
|
60 | + 'http_509' => 'Unassigned', |
|
61 | + 'http_510' => 'Not Extended', |
|
62 | + 'http_511' => 'Network Authentication Required', |
|
63 | 63 | ]; |
@@ -10,55 +10,55 @@ |
||
10 | 10 | */ |
11 | 11 | return [ |
12 | 12 | |
13 | - 'ok' => 'OK', |
|
14 | - 'no_error_message' => 'Error #:api_code', |
|
13 | + 'ok' => 'OK', |
|
14 | + 'no_error_message' => 'Error #:api_code', |
|
15 | 15 | |
16 | - // Used by Exception Handler Helper (when used) |
|
17 | - 'uncaught_exception' => 'Uncaught exception: :message', |
|
18 | - 'http_exception' => 'HTTP exception: :message', |
|
16 | + // Used by Exception Handler Helper (when used) |
|
17 | + 'uncaught_exception' => 'Uncaught exception: :message', |
|
18 | + 'http_exception' => 'HTTP exception: :message', |
|
19 | 19 | |
20 | - // HttpException handler (added in 6.4.0) |
|
21 | - // Error messages for HttpException caught w/o custom messages |
|
22 | - // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
23 | - 'http_400' => 'Bad Request', |
|
24 | - 'http_401' => 'Unauthorized', |
|
25 | - 'http_402' => 'Payment Required', |
|
26 | - 'http_403' => 'Forbidden', |
|
27 | - 'http_404' => 'Not Found', |
|
28 | - 'http_405' => 'Method Not Allowed', |
|
29 | - 'http_406' => 'Not Acceptable', |
|
30 | - 'http_407' => 'Proxy Authentication Required', |
|
31 | - 'http_408' => 'Request Timeout', |
|
32 | - 'http_409' => 'Conflict', |
|
33 | - 'http_410' => 'Gone', |
|
34 | - 'http_411' => 'Length Required', |
|
35 | - 'http_412' => 'Precondition Failed', |
|
36 | - 'http_413' => 'Payload Too Large', |
|
37 | - 'http_414' => 'URI Too Long', |
|
38 | - 'http_415' => 'Unsupported Media Type', |
|
39 | - 'http_416' => 'Range Not Satisfiable', |
|
40 | - 'http_417' => 'Expectation Failed', |
|
41 | - 'http_421' => 'Misdirected Request', |
|
42 | - 'http_422' => 'Unprocessable Entity', |
|
43 | - 'http_423' => 'Locked', |
|
44 | - 'http_424' => 'Failed Dependency', |
|
45 | - 'http_425' => 'Too Early', |
|
46 | - 'http_426' => 'Upgrade Required', |
|
47 | - 'http_428' => 'Precondition Required', |
|
48 | - 'http_429' => 'Too Many Requests', |
|
49 | - 'http_431' => 'Request Header Fields Too Large', |
|
50 | - 'http_451' => 'Unavailable For Legal Reasons', |
|
51 | - 'http_500' => 'Internal Server Error', |
|
52 | - 'http_501' => 'Not Implemented', |
|
53 | - 'http_502' => 'Bad Gateway', |
|
54 | - 'http_503' => 'Service Unavailable', |
|
55 | - 'http_504' => 'Gateway Timeout', |
|
56 | - 'http_505' => 'HTTP Version Not Supported', |
|
57 | - 'http_506' => 'Variant Also Negotiates', |
|
58 | - 'http_507' => 'Insufficient Storage', |
|
59 | - 'http_508' => 'Loop Detected', |
|
60 | - 'http_509' => 'Unassigned', |
|
61 | - 'http_510' => 'Not Extended', |
|
62 | - 'http_511' => 'Network Authentication Required', |
|
20 | + // HttpException handler (added in 6.4.0) |
|
21 | + // Error messages for HttpException caught w/o custom messages |
|
22 | + // https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
|
23 | + 'http_400' => 'Bad Request', |
|
24 | + 'http_401' => 'Unauthorized', |
|
25 | + 'http_402' => 'Payment Required', |
|
26 | + 'http_403' => 'Forbidden', |
|
27 | + 'http_404' => 'Not Found', |
|
28 | + 'http_405' => 'Method Not Allowed', |
|
29 | + 'http_406' => 'Not Acceptable', |
|
30 | + 'http_407' => 'Proxy Authentication Required', |
|
31 | + 'http_408' => 'Request Timeout', |
|
32 | + 'http_409' => 'Conflict', |
|
33 | + 'http_410' => 'Gone', |
|
34 | + 'http_411' => 'Length Required', |
|
35 | + 'http_412' => 'Precondition Failed', |
|
36 | + 'http_413' => 'Payload Too Large', |
|
37 | + 'http_414' => 'URI Too Long', |
|
38 | + 'http_415' => 'Unsupported Media Type', |
|
39 | + 'http_416' => 'Range Not Satisfiable', |
|
40 | + 'http_417' => 'Expectation Failed', |
|
41 | + 'http_421' => 'Misdirected Request', |
|
42 | + 'http_422' => 'Unprocessable Entity', |
|
43 | + 'http_423' => 'Locked', |
|
44 | + 'http_424' => 'Failed Dependency', |
|
45 | + 'http_425' => 'Too Early', |
|
46 | + 'http_426' => 'Upgrade Required', |
|
47 | + 'http_428' => 'Precondition Required', |
|
48 | + 'http_429' => 'Too Many Requests', |
|
49 | + 'http_431' => 'Request Header Fields Too Large', |
|
50 | + 'http_451' => 'Unavailable For Legal Reasons', |
|
51 | + 'http_500' => 'Internal Server Error', |
|
52 | + 'http_501' => 'Not Implemented', |
|
53 | + 'http_502' => 'Bad Gateway', |
|
54 | + 'http_503' => 'Service Unavailable', |
|
55 | + 'http_504' => 'Gateway Timeout', |
|
56 | + 'http_505' => 'HTTP Version Not Supported', |
|
57 | + 'http_506' => 'Variant Also Negotiates', |
|
58 | + 'http_507' => 'Insufficient Storage', |
|
59 | + 'http_508' => 'Loop Detected', |
|
60 | + 'http_509' => 'Unassigned', |
|
61 | + 'http_510' => 'Not Extended', |
|
62 | + 'http_511' => 'Network Authentication Required', |
|
63 | 63 | ]; |
64 | 64 |
@@ -21,180 +21,180 @@ |
||
21 | 21 | */ |
22 | 22 | class BaseApiCodes |
23 | 23 | { |
24 | - use ApiCodesHelpers; |
|
25 | - |
|
26 | - /** |
|
27 | - * protected code range - lowest code for reserved range. |
|
28 | - * |
|
29 | - * @var int |
|
30 | - */ |
|
31 | - public const RESERVED_MIN_API_CODE_OFFSET = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * protected code range - highest code for reserved range |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - public const RESERVED_MAX_API_CODE_OFFSET = 19; |
|
39 | - |
|
40 | - /** |
|
41 | - * built-in codes: OK |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected const OK_OFFSET = 0; |
|
46 | - /** |
|
47 | - * built-in code for fallback message mapping |
|
48 | - * |
|
49 | - * @var int |
|
50 | - */ |
|
51 | - protected const NO_ERROR_MESSAGE_OFFSET = 1; |
|
52 | - /** |
|
53 | - * built-in error code for HTTP_NOT_FOUND exception |
|
54 | - * |
|
55 | - * @var int |
|
56 | - */ |
|
57 | - protected const EX_HTTP_NOT_FOUND_OFFSET = 10; |
|
58 | - /** |
|
59 | - * built-in error code for HTTP_SERVICE_UNAVAILABLE exception |
|
60 | - * |
|
61 | - * @var int |
|
62 | - */ |
|
63 | - protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11; |
|
64 | - /** |
|
65 | - * built-in error code for HTTP_EXCEPTION |
|
66 | - * |
|
67 | - * @var int |
|
68 | - */ |
|
69 | - protected const EX_HTTP_EXCEPTION_OFFSET = 12; |
|
70 | - /** |
|
71 | - * built-in error code for UNCAUGHT_EXCEPTION |
|
72 | - * |
|
73 | - * @var int |
|
74 | - */ |
|
75 | - protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13; |
|
76 | - |
|
77 | - /** |
|
78 | - * built-in error code for \Illuminate\Auth\AuthenticationException |
|
79 | - * |
|
80 | - * @var int |
|
81 | - */ |
|
82 | - protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14; |
|
83 | - |
|
84 | - /** |
|
85 | - * built-in error code for \Illuminate\Auth\AuthenticationException |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - protected const EX_VALIDATION_EXCEPTION_OFFSET = 15; |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns base code mapping array |
|
93 | - * |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - protected static function getBaseMap(): array |
|
97 | - { |
|
98 | - $tpl = 'response-builder::builder.http_%d'; |
|
99 | - |
|
100 | - return [ |
|
101 | - self::OK() => 'response-builder::builder.ok', |
|
102 | - self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
103 | - self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
104 | - self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
105 | - self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
106 | - self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
107 | - self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
108 | - self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
109 | - ]; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns API code for internal code OK |
|
114 | - * |
|
115 | - * @return int valid API code in current range |
|
116 | - */ |
|
117 | - public static function OK(): int |
|
118 | - { |
|
119 | - return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns API code for internal code NO_ERROR_MESSAGE |
|
124 | - * |
|
125 | - * @return int valid API code in current range |
|
126 | - */ |
|
127 | - public static function NO_ERROR_MESSAGE(): int |
|
128 | - { |
|
129 | - return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Returns API code for internal code EX_HTTP_NOT_FOUND |
|
134 | - * |
|
135 | - * @return int valid API code in current range |
|
136 | - * |
|
137 | - * @deprecated Configure Exception Handler to use your own API code. |
|
138 | - */ |
|
139 | - public static function EX_HTTP_NOT_FOUND(): int |
|
140 | - { |
|
141 | - return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Returns API code for internal code EX_HTTP_EXCEPTION |
|
146 | - * |
|
147 | - * @return int valid API code in current range |
|
148 | - */ |
|
149 | - public static function EX_HTTP_EXCEPTION(): int |
|
150 | - { |
|
151 | - return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
|
156 | - * |
|
157 | - * @return int valid API code in current range |
|
158 | - */ |
|
159 | - public static function EX_UNCAUGHT_EXCEPTION(): int |
|
160 | - { |
|
161 | - return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
|
166 | - * |
|
167 | - * @return int valid API code in current range |
|
168 | - * |
|
169 | - * @deprecated Configure Exception Handler to use your own API code. |
|
170 | - */ |
|
171 | - public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
172 | - { |
|
173 | - return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Returns API code for internal code EX_VALIDATION_EXCEPTION |
|
178 | - * |
|
179 | - * @return int valid API code in current range |
|
180 | - * |
|
181 | - * @deprecated Configure Exception Handler to use your own API code. |
|
182 | - */ |
|
183 | - public static function EX_VALIDATION_EXCEPTION(): int |
|
184 | - { |
|
185 | - return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
|
190 | - * |
|
191 | - * @return int valid API code in current range |
|
192 | - * |
|
193 | - * @deprecated Configure Exception Handler to use your own API code. |
|
194 | - */ |
|
195 | - public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
196 | - { |
|
197 | - return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
198 | - } |
|
24 | + use ApiCodesHelpers; |
|
25 | + |
|
26 | + /** |
|
27 | + * protected code range - lowest code for reserved range. |
|
28 | + * |
|
29 | + * @var int |
|
30 | + */ |
|
31 | + public const RESERVED_MIN_API_CODE_OFFSET = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * protected code range - highest code for reserved range |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + public const RESERVED_MAX_API_CODE_OFFSET = 19; |
|
39 | + |
|
40 | + /** |
|
41 | + * built-in codes: OK |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected const OK_OFFSET = 0; |
|
46 | + /** |
|
47 | + * built-in code for fallback message mapping |
|
48 | + * |
|
49 | + * @var int |
|
50 | + */ |
|
51 | + protected const NO_ERROR_MESSAGE_OFFSET = 1; |
|
52 | + /** |
|
53 | + * built-in error code for HTTP_NOT_FOUND exception |
|
54 | + * |
|
55 | + * @var int |
|
56 | + */ |
|
57 | + protected const EX_HTTP_NOT_FOUND_OFFSET = 10; |
|
58 | + /** |
|
59 | + * built-in error code for HTTP_SERVICE_UNAVAILABLE exception |
|
60 | + * |
|
61 | + * @var int |
|
62 | + */ |
|
63 | + protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11; |
|
64 | + /** |
|
65 | + * built-in error code for HTTP_EXCEPTION |
|
66 | + * |
|
67 | + * @var int |
|
68 | + */ |
|
69 | + protected const EX_HTTP_EXCEPTION_OFFSET = 12; |
|
70 | + /** |
|
71 | + * built-in error code for UNCAUGHT_EXCEPTION |
|
72 | + * |
|
73 | + * @var int |
|
74 | + */ |
|
75 | + protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13; |
|
76 | + |
|
77 | + /** |
|
78 | + * built-in error code for \Illuminate\Auth\AuthenticationException |
|
79 | + * |
|
80 | + * @var int |
|
81 | + */ |
|
82 | + protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14; |
|
83 | + |
|
84 | + /** |
|
85 | + * built-in error code for \Illuminate\Auth\AuthenticationException |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + protected const EX_VALIDATION_EXCEPTION_OFFSET = 15; |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns base code mapping array |
|
93 | + * |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + protected static function getBaseMap(): array |
|
97 | + { |
|
98 | + $tpl = 'response-builder::builder.http_%d'; |
|
99 | + |
|
100 | + return [ |
|
101 | + self::OK() => 'response-builder::builder.ok', |
|
102 | + self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
103 | + self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
104 | + self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
105 | + self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
106 | + self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
107 | + self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
108 | + self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
109 | + ]; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns API code for internal code OK |
|
114 | + * |
|
115 | + * @return int valid API code in current range |
|
116 | + */ |
|
117 | + public static function OK(): int |
|
118 | + { |
|
119 | + return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns API code for internal code NO_ERROR_MESSAGE |
|
124 | + * |
|
125 | + * @return int valid API code in current range |
|
126 | + */ |
|
127 | + public static function NO_ERROR_MESSAGE(): int |
|
128 | + { |
|
129 | + return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Returns API code for internal code EX_HTTP_NOT_FOUND |
|
134 | + * |
|
135 | + * @return int valid API code in current range |
|
136 | + * |
|
137 | + * @deprecated Configure Exception Handler to use your own API code. |
|
138 | + */ |
|
139 | + public static function EX_HTTP_NOT_FOUND(): int |
|
140 | + { |
|
141 | + return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Returns API code for internal code EX_HTTP_EXCEPTION |
|
146 | + * |
|
147 | + * @return int valid API code in current range |
|
148 | + */ |
|
149 | + public static function EX_HTTP_EXCEPTION(): int |
|
150 | + { |
|
151 | + return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
|
156 | + * |
|
157 | + * @return int valid API code in current range |
|
158 | + */ |
|
159 | + public static function EX_UNCAUGHT_EXCEPTION(): int |
|
160 | + { |
|
161 | + return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
|
166 | + * |
|
167 | + * @return int valid API code in current range |
|
168 | + * |
|
169 | + * @deprecated Configure Exception Handler to use your own API code. |
|
170 | + */ |
|
171 | + public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
172 | + { |
|
173 | + return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Returns API code for internal code EX_VALIDATION_EXCEPTION |
|
178 | + * |
|
179 | + * @return int valid API code in current range |
|
180 | + * |
|
181 | + * @deprecated Configure Exception Handler to use your own API code. |
|
182 | + */ |
|
183 | + public static function EX_VALIDATION_EXCEPTION(): int |
|
184 | + { |
|
185 | + return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
|
190 | + * |
|
191 | + * @return int valid API code in current range |
|
192 | + * |
|
193 | + * @deprecated Configure Exception Handler to use your own API code. |
|
194 | + */ |
|
195 | + public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
196 | + { |
|
197 | + return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
@@ -15,65 +15,65 @@ discard block |
||
15 | 15 | use \Symfony\Component\HttpFoundation\Response as HttpResponse; |
16 | 16 | |
17 | 17 | return [ |
18 | - /* |
|
18 | + /* |
|
19 | 19 | |----------------------------------------------------------------------------------------------------------- |
20 | 20 | | Code range settings |
21 | 21 | |----------------------------------------------------------------------------------------------------------- |
22 | 22 | */ |
23 | - 'min_code' => 100, |
|
24 | - 'max_code' => 1024, |
|
23 | + 'min_code' => 100, |
|
24 | + 'max_code' => 1024, |
|
25 | 25 | |
26 | - /* |
|
26 | + /* |
|
27 | 27 | |----------------------------------------------------------------------------------------------------------- |
28 | 28 | | Error code to message mapping |
29 | 29 | |----------------------------------------------------------------------------------------------------------- |
30 | 30 | | |
31 | 31 | */ |
32 | - 'map' => [ |
|
33 | - // YOUR_API_CODE => '<MESSAGE_KEY>', |
|
34 | - ], |
|
32 | + 'map' => [ |
|
33 | + // YOUR_API_CODE => '<MESSAGE_KEY>', |
|
34 | + ], |
|
35 | 35 | |
36 | - /* |
|
36 | + /* |
|
37 | 37 | |----------------------------------------------------------------------------------------------------------- |
38 | 38 | | Response Builder classes |
39 | 39 | |----------------------------------------------------------------------------------------------------------- |
40 | 40 | | |
41 | 41 | */ |
42 | - 'classes' => [ |
|
43 | - \Illuminate\Database\Eloquent\Model::class => [ |
|
44 | - 'key' => 'item', |
|
45 | - 'method' => 'toArray', |
|
46 | - ], |
|
47 | - \Illuminate\Support\Collection::class => [ |
|
48 | - 'key' => 'items', |
|
49 | - 'method' => 'toArray', |
|
50 | - ], |
|
51 | - \Illuminate\Database\Eloquent\Collection::class => [ |
|
52 | - 'key' => 'items', |
|
53 | - 'method' => 'toArray', |
|
54 | - ], |
|
55 | - \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
56 | - 'key' => 'item', |
|
57 | - 'method' => 'toArray', |
|
58 | - ], |
|
59 | - ], |
|
42 | + 'classes' => [ |
|
43 | + \Illuminate\Database\Eloquent\Model::class => [ |
|
44 | + 'key' => 'item', |
|
45 | + 'method' => 'toArray', |
|
46 | + ], |
|
47 | + \Illuminate\Support\Collection::class => [ |
|
48 | + 'key' => 'items', |
|
49 | + 'method' => 'toArray', |
|
50 | + ], |
|
51 | + \Illuminate\Database\Eloquent\Collection::class => [ |
|
52 | + 'key' => 'items', |
|
53 | + 'method' => 'toArray', |
|
54 | + ], |
|
55 | + \Illuminate\Http\Resources\Json\JsonResource::class => [ |
|
56 | + 'key' => 'item', |
|
57 | + 'method' => 'toArray', |
|
58 | + ], |
|
59 | + ], |
|
60 | 60 | |
61 | - /* |
|
61 | + /* |
|
62 | 62 | |----------------------------------------------------------------------------------------------------------- |
63 | 63 | | data-to-json encoding options |
64 | 64 | |----------------------------------------------------------------------------------------------------------- |
65 | 65 | | |
66 | 66 | */ |
67 | - 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
67 | + 'encoding_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE, |
|
68 | 68 | |
69 | - /* |
|
69 | + /* |
|
70 | 70 | |----------------------------------------------------------------------------------------------------------- |
71 | 71 | | Exception handler error codes |
72 | 72 | |----------------------------------------------------------------------------------------------------------- |
73 | 73 | | |
74 | 74 | */ |
75 | - 'exception_handler' => [ |
|
76 | - /* |
|
75 | + 'exception_handler' => [ |
|
76 | + /* |
|
77 | 77 | * HTTP Exceptions |
78 | 78 | * Use this section to define how you want any Http Exception to be handled. |
79 | 79 | * This means that you can define any Http code (i.e. 404 => HttpResponse::HTTP_NOT_FOUND) |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | // 'api_code' => BaseApiCodes::EX_UNCAUGHT_EXCEPTION(), |
105 | 105 | // 'http_code' => HttpResponse::HTTP_INTERNAL_SERVER_ERROR, |
106 | 106 | // ], |
107 | - ], |
|
107 | + ], |
|
108 | 108 | |
109 | - /* |
|
109 | + /* |
|
110 | 110 | |----------------------------------------------------------------------------------------------------------- |
111 | 111 | | Debug config |
112 | 112 | |----------------------------------------------------------------------------------------------------------- |
113 | 113 | | |
114 | 114 | */ |
115 | - 'debug' => [ |
|
116 | - 'debug_key' => 'debug', |
|
117 | - 'exception_handler' => [ |
|
118 | - 'trace_key' => 'trace', |
|
119 | - 'trace_enabled' => env('APP_DEBUG', false), |
|
120 | - ], |
|
121 | - ], |
|
115 | + 'debug' => [ |
|
116 | + 'debug_key' => 'debug', |
|
117 | + 'exception_handler' => [ |
|
118 | + 'trace_key' => 'trace', |
|
119 | + 'trace_enabled' => env('APP_DEBUG', false), |
|
120 | + ], |
|
121 | + ], |
|
122 | 122 | |
123 | 123 | ]; |