Return the broken rule in the validation error response
This commit is contained in:
parent
1967e3f7fd
commit
f293c73977
1 changed files with 21 additions and 5 deletions
|
@ -169,14 +169,30 @@ class Handler extends ExceptionHandler
|
||||||
*/
|
*/
|
||||||
public function invalidJson($request, ValidationException $exception)
|
public function invalidJson($request, ValidationException $exception)
|
||||||
{
|
{
|
||||||
$errors = collect($exception->errors())->map(function ($errors, $field) use ($exception) {
|
$codes = collect($exception->validator->failed())->mapWithKeys(function ($reasons, $field) {
|
||||||
|
$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, $exception) {
|
||||||
$response = [];
|
$response = [];
|
||||||
foreach ($errors as $key => $error) {
|
foreach ($errors as $key => $error) {
|
||||||
$converted = self::convertToArray($exception)['errors'][0];
|
$meta = [
|
||||||
$response[] = array_merge($converted, [
|
|
||||||
'detail' => $error,
|
|
||||||
'source_field' => $field,
|
'source_field' => $field,
|
||||||
]);
|
'rule' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
|
||||||
|
$codes, str_replace('.', '_', $field) . '.' . $key
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
|
||||||
|
$converted = self::convertToArray($exception)['errors'][0];
|
||||||
|
$converted['detail'] = $error;
|
||||||
|
$converted['meta'] = is_array($converted['meta']) ? array_merge($converted['meta'], $meta) : $meta;
|
||||||
|
|
||||||
|
$response[] = $converted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|
Loading…
Reference in a new issue