Handle error codes from custom rules better
This commit is contained in:
parent
9905358bc3
commit
bbbab4bf81
1 changed files with 10 additions and 1 deletions
|
@ -16,6 +16,13 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Laravel's validation parser formats custom rules using the class name
|
||||||
|
* resulting in some weird rule names. This string will be parsed out and
|
||||||
|
* replaced with 'p_' in the response code.
|
||||||
|
*/
|
||||||
|
private const PTERODACTYL_RULE_STRING = 'pterodactyl\_rules\_';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of the exception types that should not be reported.
|
* A list of the exception types that should not be reported.
|
||||||
*
|
*
|
||||||
|
@ -156,7 +163,9 @@ class Handler extends ExceptionHandler
|
||||||
$response = [];
|
$response = [];
|
||||||
foreach ($errors as $key => $error) {
|
foreach ($errors as $key => $error) {
|
||||||
$response[] = [
|
$response[] = [
|
||||||
'code' => array_get($codes, str_replace('.', '_', $field) . '.' . $key),
|
'code' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
|
||||||
|
$codes, str_replace('.', '_', $field) . '.' . $key
|
||||||
|
)),
|
||||||
'detail' => $error,
|
'detail' => $error,
|
||||||
'source' => ['field' => $field],
|
'source' => ['field' => $field],
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue