ldc-bogt/app/Exceptions/Handler.php

77 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2019-12-04 17:30:46 +01:00
<?php
namespace App\Exceptions;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
2022-12-12 17:23:26 +01:00
use Sentry\Laravel\Integration;
2019-12-04 17:30:46 +01:00
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [];
2019-12-04 17:30:46 +01:00
/**
* 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.
2019-12-04 17:30:46 +01:00
*
* @return void
*/
public function register()
2019-12-04 17:30:46 +01:00
{
$this->reportable(function (\Throwable $e) {
Integration::captureUnhandledException($e);
if ($e instanceof CafelApiImageFetchException) {
$this->reportCafelApiImageErrorException($e);
return;
}
});
2019-12-04 17:30:46 +01:00
}
/**
* Report Cafel exception image.
2019-12-04 17:30:46 +01:00
*
* @param CafelApiImageFetchException $exception
* @return void
2019-12-04 17:30:46 +01:00
*/
private function reportCafelApiImageErrorException(CafelApiImageFetchException $exception): void
2019-12-04 17:30:46 +01:00
{
$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
2019-12-04 17:30:46 +01:00
}
}