From 66a17f830d2fdbbbb741eccb64ebacce07e6bac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Tue, 21 Sep 2021 09:57:42 +0200 Subject: [PATCH] composer require kwaadpepper/exception-handler --- app/Exceptions/Handler.php | 44 +------------ composer.json | 1 + composer.lock | 63 ++++++++++++++++++- config/exception-handler.php | 17 +++++ .../views/emails/exception-plain.blade.php | 10 --- resources/views/emails/exception.blade.php | 16 ----- 6 files changed, 81 insertions(+), 70 deletions(-) create mode 100644 config/exception-handler.php delete mode 100644 resources/views/emails/exception-plain.blade.php delete mode 100644 resources/views/emails/exception.blade.php diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 5892cad..19a1a9f 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,10 +2,7 @@ namespace App\Exceptions; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Illuminate\Support\Facades\Mail; -use RuntimeException; -use Throwable; +use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler; class Handler extends ExceptionHandler { @@ -29,45 +26,6 @@ class Handler extends ExceptionHandler 'password_confirmation', ]; - /** - * Report or log an exception. - * - * @param \Throwable $exception - * @return void - * - * @throws \Exception - */ - public function report(Throwable $e) - { - if (get_class($e) == RedirectTo::class) { - abort(redirect($e->url)); - } - try { - if (config('app.debug') === false) { - if ($this->shouldntReport($e)) { - return; - } - Mail::send([ - 'html' => 'emails.exception', - 'text' => 'emails.exception-plain' - ], [ - 'exception' => $e, - 'appName' => config('app.name') - ], function ($m) { - $m->to( - config('mail.contactsList.serviceweb'), - sprintf('%s Exception Handler', config('app.name')) - )->subject('Need help !, an error occured in your application, please check Logs ASAP'); - }); - } - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch - } catch (RuntimeException $e) { - // do nothing, mail send error, let laravel only handle this - } finally { - parent::report($e); - } - } - /** * Register the exception handling callbacks for the application. * diff --git a/composer.json b/composer.json index f065921..132c780 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "guzzlehttp/guzzle": "^7.0.1", "kwaadpepper/crud-policies": "^0.1.18", "kwaadpepper/enum": "^2.1", + "kwaadpepper/exception-handler": "^0.0.3", "laravel-lang/lang": "~8.0", "laravel/framework": "^8.12", "laravel/tinker": "^2.5", diff --git a/composer.lock b/composer.lock index 90b9de9..9df634c 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": "6bd42ef9c828624e25c28124d4116e32", + "content-hash": "c32404ecdf12c6d1eca2e714cb65bbb6", "packages": [ { "name": "asm89/stack-cors", @@ -1571,6 +1571,67 @@ }, "time": "2021-09-20T20:37:21+00:00" }, + { + "name": "kwaadpepper/exception-handler", + "version": "0.0.3", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/exception-handler.git", + "reference": "979e8add45fea601b221e95595366fb446e8c6b7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/979e8add45fea601b221e95595366fb446e8c6b7", + "reference": "979e8add45fea601b221e95595366fb446e8c6b7", + "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.3" + }, + "time": "2021-09-15T17:06:33+00:00" + }, { "name": "laravel-lang/lang", "version": "8.1.3", diff --git a/config/exception-handler.php b/config/exception-handler.php new file mode 100644 index 0000000..e6bd69b --- /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' => [ + env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr') + ] +]; diff --git a/resources/views/emails/exception-plain.blade.php b/resources/views/emails/exception-plain.blade.php deleted file mode 100644 index 0360447..0000000 --- a/resources/views/emails/exception-plain.blade.php +++ /dev/null @@ -1,10 +0,0 @@ -{{ $appName }} Exception Handler - -Une erreur est survenue sur le site {{ $appName }} -{{ $exception->getMessage() }} -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/emails/exception.blade.php b/resources/views/emails/exception.blade.php deleted file mode 100644 index 80a46d6..0000000 --- a/resources/views/emails/exception.blade.php +++ /dev/null @@ -1,16 +0,0 @@ - - - - {{ $appName }} Exception Handler - - - -

Une erreur est survenue sur le site {{ $appName }}

-

{{ $exception->getMessage() }}

-

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.

- -