Skip to content

Commit bbbab4b

Browse files
committed
Handle error codes from custom rules better
1 parent 9905358 commit bbbab4b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/Exceptions/Handler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
class Handler extends ExceptionHandler
1818
{
19+
/**
20+
* Laravel's validation parser formats custom rules using the class name
21+
* resulting in some weird rule names. This string will be parsed out and
22+
* replaced with 'p_' in the response code.
23+
*/
24+
private const PTERODACTYL_RULE_STRING = 'pterodactyl\_rules\_';
25+
1926
/**
2027
* A list of the exception types that should not be reported.
2128
*
@@ -156,7 +163,9 @@ public function invalidJson($request, ValidationException $exception)
156163
$response = [];
157164
foreach ($errors as $key => $error) {
158165
$response[] = [
159-
'code' => array_get($codes, str_replace('.', '_', $field) . '.' . $key),
166+
'code' => str_replace(self::PTERODACTYL_RULE_STRING, 'p_', array_get(
167+
$codes, str_replace('.', '_', $field) . '.' . $key
168+
)),
160169
'detail' => $error,
161170
'source' => ['field' => $field],
162171
];

0 commit comments

Comments
 (0)