diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 600bf9e..f34f3c8 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -13,8 +13,7 @@ namespace App\Exceptions; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Throwable; +use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler; /** * Undocumented class @@ -32,9 +31,7 @@ class Handler extends ExceptionHandler * * @var array */ - protected $dontReport = [ - // - ]; + protected $dontReport = []; /** * A list of the inputs that are never flashed for validation exceptions. @@ -46,46 +43,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') - ) - //phpcs:ignore Generic.Files.LineLength.TooLong - )->subject('Need help !, an error occured in your application, please check Logs ASAP'); - } - ); - } - } finally { - return true; - } - } - ); - } } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index e0e7dc8..671d030 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -9,6 +9,7 @@ use App\Models\Product; use App\Models\SeoDatum; use App\Models\Slide; use App\Models\Slider; +use Exception; use Illuminate\Support\Carbon; class HomeController extends Controller diff --git a/composer.json b/composer.json index df852f2..afe1f6a 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "guzzlehttp/guzzle": "^7.0.1", "joedixon/laravel-translation": "^1.1", "kwaadpepper/enum": "^2.1", + "kwaadpepper/exception-handler": "^0.0.8", "laravel/framework": "^8.65", "laravel/sanctum": "^2.11", "laravel/tinker": "^2.5", diff --git a/composer.lock b/composer.lock index 5ba1e10..375ed32 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": "9e5c04cb7369a0dfd36212e6ca2bf597", + "content-hash": "6d3d19ee0637b85edde0f49067b24cae", "packages": [ { "name": "asm89/stack-cors", @@ -1046,6 +1046,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.83.4", @@ -8222,5 +8283,5 @@ "php": "^7.3|^8.0" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.3.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 e058936..768ed8c 100644 --- a/config/mail.php +++ b/config/mail.php @@ -98,7 +98,6 @@ return [ // Contacts List 'contactsList' => [ - 'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'informatique.internet@ldc.fr'), 'contactform' => env('MAIL_LIST_CONTACTFORM', '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 @@ - - -
-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.
- -