composer require kwaadpepper/exception-handler
This commit is contained in:
parent
c98247610a
commit
91bb88d26d
7 changed files with 82 additions and 94 deletions
|
|
@ -8,16 +8,14 @@ use App\Exceptions\Api\V2\ApiErrorException;
|
|||
use App\Exceptions\Api\V2\CrmException;
|
||||
use App\Http\Resources\Api\V2\ApiResponse as V2ApiResponse;
|
||||
use App\Lib\Helper;
|
||||
use App\Mail\ExceptionAlert;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Throwable;
|
||||
|
||||
|
|
@ -66,16 +64,7 @@ class Handler extends ExceptionHandler
|
|||
if (get_class($e) == RedirectTo::class) {
|
||||
abort(redirect($e->url));
|
||||
}
|
||||
try {
|
||||
if (!config('app.debug')) {
|
||||
if ($this->shouldntReport($e)) {
|
||||
return;
|
||||
}
|
||||
Mail::send(new ExceptionAlert($e));
|
||||
}
|
||||
} finally {
|
||||
parent::report($e);
|
||||
}
|
||||
parent::report($e);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Mail\Mailable;
|
||||
|
||||
class ExceptionAlert extends Mailable
|
||||
{
|
||||
|
||||
/**
|
||||
* Undocumented variable
|
||||
*
|
||||
* @var Exception
|
||||
*/
|
||||
public $exception;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Exception $exception)
|
||||
{
|
||||
$this->exception = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->view('mail.exception')
|
||||
->subject('Need help !, an error occured in your application, please check Logs ASAP')
|
||||
->text('mail.exception-plain')
|
||||
->with('appName', config('app.name'))
|
||||
->with('appUrl', config('app.url'))
|
||||
->with('exception', $this->exception)
|
||||
->with('url', app()->runningInConsole() ? 'CONSOLE' : (
|
||||
(request() and request()->fullUrl()) ?
|
||||
request()->fullUrl() : 'none'))
|
||||
->to(
|
||||
config('mail.contactsList.serviceweb', 'informatique.internet@ldc.fr'),
|
||||
sprintf('%s Exception Handler', config('app.name'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,7 @@
|
|||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"kwaadpepper/crud-policies": "^0.1.17",
|
||||
"kwaadpepper/enum": "^2.0",
|
||||
"kwaadpepper/exception-handler": "^0.0.1",
|
||||
"laravel-lang/lang": "~7.0",
|
||||
"laravel/framework": "^8.39",
|
||||
"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": "52ddf0e771e6661178474f2a87aeaf7e",
|
||||
"content-hash": "04e9185626e4a8f3439e76f10ed8baf6",
|
||||
"packages": [
|
||||
{
|
||||
"name": "arondeparon/laravel-request-sanitizer",
|
||||
|
|
@ -1847,6 +1847,67 @@
|
|||
},
|
||||
"time": "2021-08-13T10:11:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kwaadpepper/exception-handler",
|
||||
"version": "0.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Kwaadpepper/exception-handler.git",
|
||||
"reference": "a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f",
|
||||
"reference": "a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f",
|
||||
"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.1"
|
||||
},
|
||||
"time": "2021-08-31T20:28:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel-lang/lang",
|
||||
"version": "7.0.9",
|
||||
|
|
|
|||
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' => [
|
||||
'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr')
|
||||
]
|
||||
];
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
{{ $appName }} Exception Handler
|
||||
|
||||
Une erreur est survenue sur {{ $appName }} {{ $appUrl }}
|
||||
|
||||
{{ $exception->getMessage() }}
|
||||
|
||||
url : {{ $url ?? 'none' }}
|
||||
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,18 +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>{{ config('app.name') }} Exception Handler</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<h1>Une erreur est survenue sur {{ $appName }} {{ $appUrl }}</h1>
|
||||
<h2>{{ $exception->getMessage() }}</h2>
|
||||
<p>url : {{ $url ?? 'none' }}</p>
|
||||
<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