diff --git a/src/Handlers/AbstractHandler.php b/src/Handlers/AbstractHandler.php index 31508a2..89fa9f3 100644 --- a/src/Handlers/AbstractHandler.php +++ b/src/Handlers/AbstractHandler.php @@ -2,6 +2,7 @@ namespace SMartins\Exceptions\Handlers; +use Throwable; use Exception; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; @@ -55,7 +56,7 @@ abstract class AbstractHandler * * @param Exception $e */ - public function __construct(Exception $e) + public function __construct(Throwable $e) { $this->exception = $e; } diff --git a/src/Handlers/ValidationHandler.php b/src/Handlers/ValidationHandler.php index b22b3b2..d8129e6 100644 --- a/src/Handlers/ValidationHandler.php +++ b/src/Handlers/ValidationHandler.php @@ -48,12 +48,22 @@ public function handle() */ public function getValidationTitle(array $failedFieldsRules, string $key, string $field) { - $title = __('exception::exceptions.validation.title', [ - 'fails' => strtolower(array_keys($failedFieldsRules[$field])[$key]), - 'field' => $field, - ]); + if (empty($failedFieldsRules)) { + $fails = ''; + } else { + $fails = strtolower(array_keys($failedFieldsRules[$field])[$key]); + } - return is_array($title) ? $title[0] : $title; + $title = __('exception::exceptions.validation.title', [ + 'fails' => $fails, + 'field' => $field, + ]); + + if (is_array($title)) { + $title = $title[0]; + } + + return ucfirst(trim($title)); } /** @@ -66,9 +76,12 @@ public function getValidationTitle(array $failedFieldsRules, string $key, string */ public function getValidationCode(array $failedFieldsRules, string $key, string $field) { - $rule = strtolower(array_keys($failedFieldsRules[$field])[$key]); + if (empty($failedFieldsRules)) { + return config('json-exception-handler.codes.validation'); + } - return config('json-exception-handler.codes.validation_fields.'.$field.'.'.$rule); + $rule = strtolower(array_keys($failedFieldsRules[$field])[$key]); + return config('json-exception-handler.codes.validation_fields.' . $field . '.' . $rule); } /**