Skip to content

Commit

Permalink
Fixed Some Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidreza2005 committed Nov 8, 2020
1 parent 2fa383e commit 040731e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/ApiErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace hamidreza2005\LaravelApiErrorHandler\Traits;

use hamidreza2005\LaravelApiErrorHandler\Exceptions\DefaultException;
use hamidreza2005\LaravelApiErrorHandler\Exceptions\ServerInternalException;
use Illuminate\Support\Facades\Response;

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();
Expand Down

0 comments on commit 040731e

Please sign in to comment.