Skip to content

Commit

Permalink
refactor(app): Modify boot method in AppServiceProvider.php
Browse files Browse the repository at this point in the history
- Update the `boot` method in the `app/Providers/AppServiceProvider.php` file to skip exception notification in certain environments
- Add logic to skip exception notification in local and testing environments
- Add logic to skip specific exceptions from being reported
  • Loading branch information
guanguans committed May 9, 2024
1 parent a40bd4c commit f69e192
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ php artisan exception-notify:test --ansi -v
|------------------------------|------------------------------|------------------------------|
| ![xiZhi-1](docs/xiZhi-1.jpg) | ![xiZhi-2](docs/xiZhi-2.jpg) | ![xiZhi-3](docs/xiZhi-3.jpg) |

### Skip report

Modify the `boot` method in the `app/Providers/AppServiceProvider.php` file

```php
<?php

use Guanguans\LaravelExceptionNotify\ExceptionNotifyManager;
use Illuminate\Support\Arr;

public function boot(): void
{
ExceptionNotifyManager::skipWhen(static function (\Throwable $throwable) {
if (app()->environment(['local', 'testing'])) {
return true;
}

return Arr::first(
[
Symfony\Component\HttpKernel\Exception\HttpException::class,
Illuminate\Http\Exceptions\HttpResponseException::class,
],
static fn (string $type): bool => $throwable instanceof $type
);
});
}
```

## Extend custom channel

Modify the `boot` method in the `app/Providers/AppServiceProvider.php` file
Expand Down
18 changes: 0 additions & 18 deletions config/exception-notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@
*/
'enabled' => (bool) env('EXCEPTION_NOTIFY_ENABLED', true),

/**
* The list of environments that should be reported.
*/
'env' => env_explode('EXCEPTION_NOTIFY_ENV', [
// 'production',
// 'local',
// 'testing',
'*',
]),

/**
* The list of exception that should not be reported.
*/
'except' => [
// Symfony\Component\HttpKernel\Exception\HttpException::class,
// Illuminate\Http\Exceptions\HttpResponseException::class,
],

/**
* The rate limit of same exception.
*/
Expand Down
8 changes: 0 additions & 8 deletions src/ExceptionNotifyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ private function shouldntReport(\Throwable $throwable): bool
return true;
}

if (!$this->container->environment(config('exception-notify.env'))) {
return true;
}

if (Arr::first(config('exception-notify.except'), static fn (string $type): bool => $throwable instanceof $type)) {
return true;
}

if ($this->shouldSkip($throwable)) {
return true;
}
Expand Down

0 comments on commit f69e192

Please sign in to comment.