X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/82a8db373961d89ab1c9a3736ba5fc467fe2e03d..refs/pull/2700/head:/app/Exceptions/Handler.php diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 284d731d7..196897164 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,13 +3,10 @@ namespace BookStack\Exceptions; use Exception; -use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; -use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Illuminate\Validation\ValidationException; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -17,35 +14,42 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class Handler extends ExceptionHandler { /** - * A list of the exception types that should not be reported. + * A list of the exception types that are not reported. * * @var array */ protected $dontReport = [ - AuthorizationException::class, - HttpException::class, - ModelNotFoundException::class, - ValidationException::class, + NotFoundException::class, + ]; + + /** + * A list of the inputs that are never flashed for validation exceptions. + * + * @var array + */ + protected $dontFlash = [ + 'password', + 'password_confirmation', ]; /** * Report or log an exception. - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. * - * @param \Exception $e - * @return mixed + * @param Exception $exception + * @return void + * * @throws Exception */ - public function report(Exception $e) + public function report(Exception $exception) { - return parent::report($e); + parent::report($exception); } /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request - * @param \Exception $e + * @param Exception $e * @return \Illuminate\Http\Response */ public function render($request, Exception $e) @@ -57,7 +61,10 @@ class Handler extends ExceptionHandler // Handle notify exceptions which will redirect to the // specified location then show a notification message. if ($this->isExceptionType($e, NotifyException::class)) { - session()->flash('error', $this->getOriginalMessage($e)); + $message = $this->getOriginalMessage($e); + if (!empty($message)) { + session()->flash('error', $message); + } return redirect($e->redirectLocation); } @@ -114,11 +121,8 @@ class Handler extends ExceptionHandler /** * Check the exception chain to compare against the original exception type. - * @param Exception $e - * @param $type - * @return bool */ - protected function isExceptionType(Exception $e, $type) + protected function isExceptionType(Exception $e, string $type): bool { do { if (is_a($e, $type)) { @@ -130,10 +134,8 @@ class Handler extends ExceptionHandler /** * Get original exception message. - * @param Exception $e - * @return string */ - protected function getOriginalMessage(Exception $e) + protected function getOriginalMessage(Exception $e): string { do { $message = $e->getMessage();