Handler updates

This commit is contained in:
Dane Everitt
2021-01-23 11:51:48 -08:00
parent 42ba866b26
commit 2a2072cef0

View File

@@ -43,17 +43,6 @@ class Handler extends ExceptionHandler
ValidationException::class, ValidationException::class,
]; ];
/**
* A list of exceptions that should be logged with cleaned stack
* traces to avoid exposing credentials or other sensitive information.
*
* @var array
*/
protected $cleanStacks = [
PDOException::class,
Swift_TransportException::class,
];
/** /**
* A list of the inputs that are never flashed for validation exceptions. * A list of the inputs that are never flashed for validation exceptions.
* *
@@ -67,45 +56,27 @@ class Handler extends ExceptionHandler
]; ];
/** /**
* Report or log an exception. Skips Laravel's internal reporter since we * Registers the exception handling callbacks for the application. This
* don't need or want the user information in our logs by default. * will capture specific exception types that we do not want to include
* * the detailed stack traces for since they could reveal credentials to
* If you want to implement logging in a different format to integrate with * whoever can read the logs.
* services such as AWS Cloudwatch or other monitoring you can replace the
* contents of this function with a call to the parent reporter.
*
* @param \Throwable $exception
* @return mixed
*
* @throws \Throwable
*/ */
public function report(Throwable $exception) public function register()
{ {
if (! config('app.exceptions.report_all', false) && $this->shouldntReport($exception)) { if (config('app.exceptions.report_all', false)) {
return null; $this->dontReport = [];
} }
if (method_exists($exception, 'report')) { $this->reportable(function (PDOException &$ex) {
return $exception->report(); $ex = $this->generateCleanedExceptionStack($ex);
} });
try { $this->reportable(function (Swift_TransportException &$ex) {
$logger = $this->container->make(LoggerInterface::class); $ex = $this->generateCleanedExceptionStack($ex);
} catch (Exception $ex) { });
throw $exception;
}
foreach ($this->cleanStacks as $class) {
if ($exception instanceof $class) {
$exception = $this->generateCleanedExceptionStack($exception);
break;
}
}
return $logger->error($exception);
} }
private function generateCleanedExceptionStack(Throwable $exception) private function generateCleanedExceptionStack(Throwable $exception): string
{ {
$cleanedStack = ''; $cleanedStack = '';
foreach ($exception->getTrace() as $index => $item) { foreach ($exception->getTrace() as $index => $item) {
@@ -262,7 +233,7 @@ class Handler extends ExceptionHandler
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception * @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/ */
protected function unauthenticated($request, AuthenticationException $exception) protected function unauthenticated($request, AuthenticationException $exception)
{ {