Handle error codes from custom rules better

This commit is contained in:
Dane Everitt 2018-03-04 22:21:23 -06:00
parent 9905358bc3
commit bbbab4bf81
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -16,6 +16,13 @@ use Illuminate\Foundation\Exceptions\Handler as 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.
*
@ -156,7 +163,9 @@ class Handler extends ExceptionHandler
$response = [];
foreach ($errors as $key => $error) {
$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,
'source' => ['field' => $field],
];