From 058916da34a2036d98a3f7d74e79bdff270c03bd Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Wed, 18 May 2022 12:16:18 +0200 Subject: [PATCH] Add Exception Handler package --- .env.example | 1 + README.md | 1 - app/Exceptions/Handler.php | 68 ++---------------------------------- composer.json | 1 + composer.lock | 63 ++++++++++++++++++++++++++++++++- config/exception-handler.php | 15 ++++++++ config/mail.php | 6 ---- 7 files changed, 81 insertions(+), 74 deletions(-) create mode 100644 config/exception-handler.php diff --git a/.env.example b/.env.example index 287aa3d..4c72d89 100644 --- a/.env.example +++ b/.env.example @@ -28,6 +28,7 @@ MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" +MAIL_LIST_SERVICEWEB= STATIC_FOLDERS="1" BRAND="TEST" diff --git a/README.md b/README.md index 8338083..d74d059 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ php artisan user:create # TODO - Nettoyer tous les controllers - Utiliser requests + validate -- Enlever le handler mano pour mettre le package - Checker le contenu des mails envoyés - Enlever l'utilisation de VueJS si pas nécessaire. (ex: EditUserComponent) - Supprimer la table password_resets diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 1dfe44c..ed2469d 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 { @@ -14,9 +11,7 @@ class Handler extends ExceptionHandler * * @var array */ - protected $dontReport = [ - // - ]; + protected $dontReport = []; /** * A list of the inputs that are never flashed for validation exceptions. @@ -27,63 +22,4 @@ class Handler extends ExceptionHandler 'password', 'password_confirmation', ]; - - /** - * Register the exception handling callbacks for the application. - * - * @return void - */ - public function register() - { - $this->reportable(function (Throwable $e) { - try { - if (!config('app.debug')) { - if ($this->shouldntReport($e)) { - return false; - } - 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'); - }); - } - } finally { - return true; - } - }); - } - - /** - * Report or log an exception. - * - * @param \Throwable $exception - * @return void - * - * @throws \Throwable - */ - public function report(Throwable $exception) - { - parent::report($exception); - } - - /** - * Render an exception into an HTTP response. - * - * @param \Illuminate\Http\Request $request - * @param \Throwable $exception - * @return \Symfony\Component\HttpFoundation\Response - * - * @throws \Throwable - */ - public function render($request, Throwable $exception) - { - return parent::render($request, $exception); - } } diff --git a/composer.json b/composer.json index af23b88..0e80713 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "fideloper/proxy": "^4.0", "google/cloud-vision": "^0.25.0", "kwaadpepper/enum": "^2.1", + "kwaadpepper/exception-handler": "^0.0.8", "laravel/framework": "^8.0", "laravel/tinker": "^2.0", "laravel/ui": "^3.0", diff --git a/composer.lock b/composer.lock index 7c25233..50ed363 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": "788ccec969d3e50c1708f733bd96c886", + "content-hash": "e30b5e02d039c9551c76c1b35dfcd7ee", "packages": [ { "name": "brick/math", @@ -1300,6 +1300,67 @@ }, "time": "2021-11-18T16:52:08+00:00" }, + { + "name": "kwaadpepper/exception-handler", + "version": "0.0.8", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/exception-handler.git", + "reference": "e8ba0e31ca2bf5971e459c623f0f5322a4c7a630" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/e8ba0e31ca2bf5971e459c623f0f5322a4c7a630", + "reference": "e8ba0e31ca2bf5971e459c623f0f5322a4c7a630", + "shasum": "" + }, + "require": { + "illuminate/support": "~7|~8|~9", + "laravel/framework": "~7|~8|~9" + }, + "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.8" + }, + "time": "2022-02-03T15:23:22+00:00" + }, { "name": "laravel/framework", "version": "v8.54.0", diff --git a/config/exception-handler.php b/config/exception-handler.php new file mode 100644 index 0000000..367b948 --- /dev/null +++ b/config/exception-handler.php @@ -0,0 +1,15 @@ + !config('app.debug'), + + /** + * Put a developper secured mailbox in here + * so you can receive email if things go mad + */ + 'contactsList' => explode(",", env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr')) +]; diff --git a/config/mail.php b/config/mail.php index f748d2e..3c65eb3 100644 --- a/config/mail.php +++ b/config/mail.php @@ -60,12 +60,6 @@ return [ 'name' => env('MAIL_FROM_NAME', 'Example'), ], - - // Contacts List - 'contactsList' => [ - 'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'informatique.internet@ldc.fr') - ], - /* |-------------------------------------------------------------------------- | E-Mail Encryption Protocol