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.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Illuminate\Auth\AuthenticationException $exception
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
protected function unauthenticated($request, AuthenticationException $exception)
|
|
|
|
{
|
|
|
|
return $request->expectsJson()
|
|
|
|
? response()->json(['message' => $exception->getMessage()], 401)
|
2024-01-15 11:14:47 +00:00
|
|
|
: redirect(front_url('login'));
|
2022-09-20 19:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function report(Throwable $exception)
|
|
|
|
{
|
|
|
|
if ($this->shouldReport($exception) ) {
|
|
|
|
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)
|
|
|
|
{
|
2023-08-10 14:49:36 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|