Exception Handler
This commit is contained in:
parent
c51abd57d2
commit
95b8e20ba3
5 changed files with 62 additions and 3 deletions
|
|
@ -27,6 +27,7 @@ MAIL_PASSWORD=null
|
|||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS=null
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
MAIL_ADMIN=informatique.internet@ldc.fr
|
||||
|
||||
# CRM
|
||||
CRM_ENDPOINT=
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
|
|
@ -32,11 +34,37 @@ class Handler extends ExceptionHandler
|
|||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
public function report(Throwable $e)
|
||||
{
|
||||
parent::report($exception);
|
||||
if (get_class($e) == RedirectTo::class) {
|
||||
abort(redirect($e->url));
|
||||
}
|
||||
try {
|
||||
if (!config('app.debug')) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ return [
|
|||
// Mail admin pour l'envoi de mail comme la fin de la génération des codes uniques
|
||||
'MAIL_ADMIN' => env('MAIL_ADMIN'),
|
||||
|
||||
'contactsList' => [
|
||||
'serviceweb' => env('MAIL_ADMIN', 'informatique.internet@ldc.fr')
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|
|
|
|||
10
resources/views/emails/exception-plain.blade.php
Normal file
10
resources/views/emails/exception-plain.blade.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{{ $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.
|
||||
16
resources/views/emails/exception.blade.php
Normal file
16
resources/views/emails/exception.blade.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<!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