feat: Add Flare support
- Add new log channel "flare" and update "stack" channel to use it - Introduce placeholders for log messages in several channels - Add processors to "papertrail" and "stderr" channels - Add `spatie/laravel-ignition` package to composer requirements - Change `$dontReport` variable to `$dontFlash` in exception handler - Add `FLARE_KEY` and `BRIDGY_MASTODON_TOKEN` to `.env.github` and `.env.example` files
This commit is contained in:
parent
4d9989b37b
commit
79b9013707
6 changed files with 337 additions and 383 deletions
|
@ -2,90 +2,29 @@
|
|||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, class-string<\Throwable>>
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontReport = [
|
||||
NotFoundHttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws Throwable
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function report(Throwable $e): void
|
||||
public function register(): void
|
||||
{
|
||||
parent::report($e);
|
||||
|
||||
if (config('logging.slack') && $this->shouldReport($e)) {
|
||||
$guzzle = new Client([
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$exceptionName = get_class($e) ?? 'Unknown Exception';
|
||||
$title = $exceptionName . ': ' . $e->getMessage();
|
||||
|
||||
$guzzle->post(
|
||||
config('logging.slack'),
|
||||
[
|
||||
'body' => json_encode([
|
||||
'attachments' => [[
|
||||
'fallback' => 'There was an exception.',
|
||||
'pretext' => 'There was an exception.',
|
||||
'color' => '#d00000',
|
||||
'author_name' => app()->environment(),
|
||||
'author_link' => config('app.url'),
|
||||
'fields' => [[
|
||||
'title' => $title,
|
||||
'value' => request()->method() . ' ' . request()->fullUrl(),
|
||||
]],
|
||||
'ts' => time(),
|
||||
]],
|
||||
]),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function render($request, Throwable $throwable)
|
||||
{
|
||||
if ($throwable instanceof TokenMismatchException) {
|
||||
Route::getRoutes()->match($request);
|
||||
}
|
||||
|
||||
return parent::render($request, $throwable);
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue