76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Exceptions;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
use Sentry\Laravel\Integration;
|
|
|
|
class Handler extends ExceptionHandler
|
|
{
|
|
/**
|
|
* A list of the exception types that are not reported.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dontReport = [];
|
|
|
|
/**
|
|
* A list of the inputs that are never flashed for validation exceptions.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dontFlash = [
|
|
'password',
|
|
'password_confirmation',
|
|
];
|
|
|
|
/**
|
|
* Register the exception handling callbacks for the application.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->reportable(function (\Throwable $e) {
|
|
Integration::captureUnhandledException($e);
|
|
if ($e instanceof CafelApiImageFetchException) {
|
|
$this->reportCafelApiImageErrorException($e);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Report Cafel exception image.
|
|
*
|
|
* @param CafelApiImageFetchException $exception
|
|
* @return void
|
|
*/
|
|
private function reportCafelApiImageErrorException(CafelApiImageFetchException $exception): void
|
|
{
|
|
$dest = config('exception-handler.invalidCafelImage', config('mail.from.address'));
|
|
try {
|
|
if ($dest and config('exception-handler.enableMaiLog')) {
|
|
Mail::send([
|
|
'html' => 'mails.invalidCafelImage'
|
|
], [
|
|
'appName' => config('app.name'),
|
|
'emessage' => $exception->getMessage(),
|
|
], function ($m) use ($dest) {
|
|
/** @var \Illuminate\Mail\Message $m */
|
|
$m->to(
|
|
$dest,
|
|
sprintf('%s Exception Handler', config('app.name'))
|
|
)->subject(sprintf(
|
|
'%s : Api Cafel, l\'image va être ignoré car elle est invalide.',
|
|
config('app.name')
|
|
));
|
|
});
|
|
}
|
|
} catch (\Exception $e) {
|
|
Log::critical('Handler could not send Exception email', ['exception' => $e]);
|
|
} //end try
|
|
}
|
|
}
|