Add Handler Exception package

This commit is contained in:
Vincent BRIDIER 2022-05-19 10:22:56 +02:00
parent 5b85ba36df
commit 69fdadd330
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
8 changed files with 82 additions and 76 deletions

View file

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

View file

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

View file

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

65
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": "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"
}

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

@ -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')
],

View file

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

View file

@ -1,16 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{{ $appName }} Exception Handler</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>Une erreur est survenue sur le site {{ $appName }}</h1>
<h2>{{ $exception->getMessage() }}</h2>
<p>date : {{ date('Y-m-d H:i:s') }}</p>
<p>code : {{$exception->getCode() }}</p>
<p>file : {{$exception->getFile() }}</p>
<p>line : {{$exception->getLine() }}</p>
<p>Veuillez vérifier les logs pour en voir la trace.</p>
</body>
</html>