From 040731ed2824c71a35e0c9683c31e9032e762255 Mon Sep 17 00:00:00 2001 From: Hamidreza Hassani Date: Sun, 8 Nov 2020 18:03:49 +0330 Subject: [PATCH] Fixed Some Bugs --- README.md | 2 ++ src/Traits/ApiErrorHandler.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af37a45..19256ca 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,8 @@ return [ "ErrorException" => "myNamespace\MyException" ]; ``` +### :exclamation_mark: Notice +**if an unknown Exception appeared this package automaticlly show it in the response but if you don't want that you can set `APP_DEBUG` to `false` in `.env` . if `APP_DEBUG` is `false` Server Internal showen in response** ## :scroll: License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/src/Traits/ApiErrorHandler.php b/src/Traits/ApiErrorHandler.php index 70ddc7c..473e45b 100644 --- a/src/Traits/ApiErrorHandler.php +++ b/src/Traits/ApiErrorHandler.php @@ -3,6 +3,7 @@ namespace hamidreza2005\LaravelApiErrorHandler\Traits; use hamidreza2005\LaravelApiErrorHandler\Exceptions\DefaultException; +use hamidreza2005\LaravelApiErrorHandler\Exceptions\ServerInternalException; use Illuminate\Support\Facades\Response; trait ApiErrorHandler @@ -10,7 +11,7 @@ trait ApiErrorHandler public function handleError($exception) { $exceptions = config("api-error-handler") ?? []; - $class = array_key_exists(get_class($exception),$exceptions) ? $exceptions[get_class($exception)] : DefaultException::class; + $class = array_key_exists(get_class($exception),$exceptions) ? $exceptions[get_class($exception)] : (config('app.debug') ? DefaultException::class : ServerInternalException::class ); $handler = new $class($exception); $handler->handleStatusCode(); $handler->handleMessage();