From 1a3c7bf67fc1727c2ce90c0a37b54ccb5f7d66d6 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Wed, 27 Apr 2022 19:31:27 +0430 Subject: [PATCH] feat!: in case of an `exception with empty error bag` return {} instead of [] --- Abstracts/Exceptions/Exception.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Abstracts/Exceptions/Exception.php b/Abstracts/Exceptions/Exception.php index a7567573b..9900aec3f 100644 --- a/Abstracts/Exceptions/Exception.php +++ b/Abstracts/Exceptions/Exception.php @@ -5,6 +5,7 @@ use Exception as BaseException; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Log; +use stdClass; use Throwable; abstract class Exception extends BaseException @@ -70,7 +71,7 @@ public function withErrors(array $errors, bool $override = true): Exception return $this; } - public function getErrors(): array + public function getErrors(): array|stdClass { $translatedErrors = []; @@ -90,6 +91,6 @@ public function getErrors(): array $translatedErrors[$key] = $translatedValues; } - return $translatedErrors; + return empty($translatedErrors) ? new stdClass(): $translatedErrors; } }