Add Exception Handler package

This commit is contained in:
Vincent BRIDIER 2022-05-18 12:16:18 +02:00
parent 322240ee50
commit 058916da34
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
7 changed files with 81 additions and 74 deletions

View file

@ -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"

View file

@ -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

View file

@ -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);
}
}

View file

@ -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",

63
composer.lock generated
View file

@ -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",

View file

@ -0,0 +1,15 @@
<?php
return [
/**
* Send mail when app debug is turn off
* so you can be warned if an unhandled exception occurs
*/
'enableMaiLog' => !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'))
];

View file

@ -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