diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 9f20eff..15f9fb3 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -8,16 +8,14 @@ use App\Exceptions\Api\V2\ApiErrorException; use App\Exceptions\Api\V2\CrmException; use App\Http\Resources\Api\V2\ApiResponse as V2ApiResponse; use App\Lib\Helper; -use App\Mail\ExceptionAlert; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; use Illuminate\Database\Eloquent\ModelNotFoundException; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Mail; use Illuminate\Validation\ValidationException; +use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Throwable; @@ -66,16 +64,7 @@ class Handler extends ExceptionHandler if (get_class($e) == RedirectTo::class) { abort(redirect($e->url)); } - try { - if (!config('app.debug')) { - if ($this->shouldntReport($e)) { - return; - } - Mail::send(new ExceptionAlert($e)); - } - } finally { - parent::report($e); - } + parent::report($e); } /** diff --git a/app/Mail/ExceptionAlert.php b/app/Mail/ExceptionAlert.php deleted file mode 100644 index 48ca654..0000000 --- a/app/Mail/ExceptionAlert.php +++ /dev/null @@ -1,49 +0,0 @@ -exception = $exception; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - return $this->view('mail.exception') - ->subject('Need help !, an error occured in your application, please check Logs ASAP') - ->text('mail.exception-plain') - ->with('appName', config('app.name')) - ->with('appUrl', config('app.url')) - ->with('exception', $this->exception) - ->with('url', app()->runningInConsole() ? 'CONSOLE' : ( - (request() and request()->fullUrl()) ? - request()->fullUrl() : 'none')) - ->to( - config('mail.contactsList.serviceweb', 'informatique.internet@ldc.fr'), - sprintf('%s Exception Handler', config('app.name')) - ); - } -} diff --git a/composer.json b/composer.json index b4fc2b5..a754ddd 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "guzzlehttp/guzzle": "^7.0.1", "kwaadpepper/crud-policies": "^0.1.17", "kwaadpepper/enum": "^2.0", + "kwaadpepper/exception-handler": "^0.0.1", "laravel-lang/lang": "~7.0", "laravel/framework": "^8.39", "laravel/tinker": "^2.5", diff --git a/composer.lock b/composer.lock index 146429d..e1b9812 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "52ddf0e771e6661178474f2a87aeaf7e", + "content-hash": "04e9185626e4a8f3439e76f10ed8baf6", "packages": [ { "name": "arondeparon/laravel-request-sanitizer", @@ -1847,6 +1847,67 @@ }, "time": "2021-08-13T10:11:43+00:00" }, + { + "name": "kwaadpepper/exception-handler", + "version": "0.0.1", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/exception-handler.git", + "reference": "a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f", + "reference": "a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f", + "shasum": "" + }, + "require": { + "illuminate/support": "~7|~8", + "laravel/framework": "~7|~8" + }, + "require-dev": { + "orchestra/testbench": "^6.13", + "phpunit/phpunit": "~9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\ExceptionHandler\\ExceptionHandlerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\ExceptionHandler\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Send emails when exceptions occurs", + "homepage": "https://github.com/kwaadpepper/exception-handler", + "keywords": [ + "email", + "exception", + "laravel", + "policies" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/exception-handler/issues", + "source": "https://github.com/Kwaadpepper/exception-handler/tree/0.0.1" + }, + "time": "2021-08-31T20:28:29+00:00" + }, { "name": "laravel-lang/lang", "version": "7.0.9", diff --git a/config/exception-handler.php b/config/exception-handler.php new file mode 100644 index 0000000..5dcf39d --- /dev/null +++ b/config/exception-handler.php @@ -0,0 +1,17 @@ + !config('app.debug'), + + /** + * Put a developper secured mailbox in here + * so you can receive email if things go mad + */ + 'contactsList' => [ + 'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr') + ] +]; diff --git a/resources/views/mail/exception-plain.blade.php b/resources/views/mail/exception-plain.blade.php deleted file mode 100644 index 966ae73..0000000 --- a/resources/views/mail/exception-plain.blade.php +++ /dev/null @@ -1,13 +0,0 @@ -{{ $appName }} Exception Handler - -Une erreur est survenue sur {{ $appName }} {{ $appUrl }} - -{{ $exception->getMessage() }} - -url : {{ $url ?? 'none' }} -date : {{ date('Y-m-d H:i:s') }} -code : {{$exception->getCode() }} -file : {{$exception->getFile() }} -line : {{$exception->getLine() }} - -Veuillez vérifier les logs pour en voir la trace. diff --git a/resources/views/mail/exception.blade.php b/resources/views/mail/exception.blade.php deleted file mode 100644 index 18e4298..0000000 --- a/resources/views/mail/exception.blade.php +++ /dev/null @@ -1,18 +0,0 @@ - - - - {{ config('app.name') }} Exception Handler - - - -

Une erreur est survenue sur {{ $appName }} {{ $appUrl }}

-

{{ $exception->getMessage() }}

-

url : {{ $url ?? 'none' }}

-

date : {{ date('Y-m-d H:i:s') }}

-

code : {{$exception->getCode() }}

-

file : {{$exception->getFile() }}

-

line : {{$exception->getLine() }}

-

Veuillez vérifier les logs pour en voir la trace.

- - -