Treat validation errors the same as a normal error; match the output exactly
This commit is contained in:
parent
8c98264eed
commit
e863683582
1 changed files with 8 additions and 17 deletions
|
@ -169,25 +169,14 @@ class Handler extends ExceptionHandler
|
||||||
*/
|
*/
|
||||||
public function invalidJson($request, ValidationException $exception)
|
public function invalidJson($request, ValidationException $exception)
|
||||||
{
|
{
|
||||||
$codes = collect($exception->validator->failed())->mapWithKeys(function ($reasons, $field) {
|
$errors = collect($exception->errors())->map(function ($errors, $field) use ($exception) {
|
||||||
$cleaned = [];
|
|
||||||
foreach ($reasons as $reason => $attrs) {
|
|
||||||
$cleaned[] = snake_case($reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [str_replace('.', '_', $field) => $cleaned];
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
$errors = collect($exception->errors())->map(function ($errors, $field) use ($codes) {
|
|
||||||
$response = [];
|
$response = [];
|
||||||
foreach ($errors as $key => $error) {
|
foreach ($errors as $key => $error) {
|
||||||
$response[] = [
|
$converted = self::convertToArray($exception)['errors'][0];
|
||||||
'code' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
|
$response[] = array_merge($converted, [
|
||||||
$codes, str_replace('.', '_', $field) . '.' . $key
|
|
||||||
)),
|
|
||||||
'detail' => $error,
|
'detail' => $error,
|
||||||
'source' => ['field' => $field],
|
'source_field' => $field,
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@ -209,7 +198,9 @@ class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
$error = [
|
$error = [
|
||||||
'code' => class_basename($exception),
|
'code' => class_basename($exception),
|
||||||
'status' => method_exists($exception, 'getStatusCode') ? strval($exception->getStatusCode()) : '500',
|
'status' => method_exists($exception, 'getStatusCode')
|
||||||
|
? strval($exception->getStatusCode())
|
||||||
|
: ($exception instanceof ValidationException ? '422' : '500'),
|
||||||
'detail' => 'An error was encountered while processing this request.',
|
'detail' => 'An error was encountered while processing this request.',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue