From 2a2072cef0f652f85cbb160ecfc905805a54e469 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 23 Jan 2021 11:51:48 -0800 Subject: [PATCH] Handler updates --- app/Exceptions/Handler.php | 59 ++++++++++---------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 00484d94..9a928793 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -43,17 +43,6 @@ class Handler extends ExceptionHandler 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. * @@ -67,45 +56,27 @@ class Handler extends ExceptionHandler ]; /** - * Report or log an exception. Skips Laravel's internal reporter since we - * don't need or want the user information in our logs by default. - * - * If you want to implement logging in a different format to integrate with - * 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 + * Registers the exception handling callbacks for the application. This + * will capture specific exception types that we do not want to include + * the detailed stack traces for since they could reveal credentials to + * whoever can read the logs. */ - public function report(Throwable $exception) + public function register() { - if (! config('app.exceptions.report_all', false) && $this->shouldntReport($exception)) { - return null; + if (config('app.exceptions.report_all', false)) { + $this->dontReport = []; } - if (method_exists($exception, 'report')) { - return $exception->report(); - } + $this->reportable(function (PDOException &$ex) { + $ex = $this->generateCleanedExceptionStack($ex); + }); - try { - $logger = $this->container->make(LoggerInterface::class); - } catch (Exception $ex) { - throw $exception; - } - - foreach ($this->cleanStacks as $class) { - if ($exception instanceof $class) { - $exception = $this->generateCleanedExceptionStack($exception); - break; - } - } - - return $logger->error($exception); + $this->reportable(function (Swift_TransportException &$ex) { + $ex = $this->generateCleanedExceptionStack($ex); + }); } - private function generateCleanedExceptionStack(Throwable $exception) + private function generateCleanedExceptionStack(Throwable $exception): string { $cleanedStack = ''; foreach ($exception->getTrace() as $index => $item) { @@ -262,7 +233,7 @@ class Handler extends ExceptionHandler * * @param \Illuminate\Http\Request $request * @param \Illuminate\Auth\AuthenticationException $exception - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse */ protected function unauthenticated($request, AuthenticationException $exception) {