composer require kwaadpepper/exception-handler
This commit is contained in:
parent
f310cb9e2d
commit
66a17f830d
6 changed files with 81 additions and 70 deletions
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
63
composer.lock
generated
63
composer.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
17
config/exception-handler.php
Normal file
17
config/exception-handler.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?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' => [
|
||||
env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr')
|
||||
]
|
||||
];
|
||||
|
|
@ -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.
|
||||
|
|
@ -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>
|
||||
Loading…
Add table
Reference in a new issue