2022-09-20 19:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Exceptions;
|
|
|
|
|
|
|
|
use Illuminate\Auth\AuthenticationException;
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class Handler extends ExceptionHandler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A list of the exception types that are not reported.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dontReport = [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of the exception types that are not reported to Sentry.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $sentryDontReport = [
|
|
|
|
//
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of the inputs that are never flashed for validation exceptions.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dontFlash = [
|
|
|
|
'password',
|
|
|
|
'password_confirmation',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an authentication exception into a response.
|
|
|
|
*/
|
|
|
|
protected function unauthenticated($request, AuthenticationException $exception)
|
|
|
|
{
|
2024-01-16 16:40:28 +00:00
|
|
|
return response()->json(['message' => $exception->getMessage()], 401);
|
2022-09-20 19:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function report(Throwable $exception)
|
|
|
|
{
|
2024-02-23 10:54:12 +00:00
|
|
|
if ($this->shouldReport($exception)) {
|
2022-09-20 19:59:52 +00:00
|
|
|
if (app()->bound('sentry') && $this->sentryShouldReport($exception)) {
|
|
|
|
app('sentry')->captureException($exception);
|
|
|
|
Log::debug('Un-handled Exception: '.$exception->getMessage(), [
|
|
|
|
'exception' => $exception,
|
|
|
|
'file' => $exception->getFile(),
|
|
|
|
'line' => $exception->getLine(),
|
|
|
|
'trace' => $exception->getTrace(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::report($exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render($request, Throwable $e)
|
|
|
|
{
|
2024-02-23 10:54:12 +00:00
|
|
|
if ($this->shouldReport($e) && ! in_array(\App::environment(), ['testing']) && config('logging.channels.slack.enabled')) {
|
2022-09-20 19:59:52 +00:00
|
|
|
Log::channel('slack')->error($e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::render($request, $e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function sentryShouldReport(Throwable $e)
|
|
|
|
{
|
|
|
|
foreach ($this->sentryDontReport as $exceptionType) {
|
|
|
|
if ($e instanceof $exceptionType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-02-23 10:54:12 +00:00
|
|
|
|
2022-09-20 19:59:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|