namespace BookStack\Exceptions;
-use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Exceptions\PostTooLargeException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
+use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;
use Symfony\Component\ErrorHandler\Error\FatalError;
+use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Throwable;
/**
* A list of the exception types that are not reported.
*
- * @var array<int, class-string<\Throwable>>
+ * @var array<int, class-string<Throwable>>
*/
protected $dontReport = [
NotFoundException::class,
* If it returns a response, that will be provided back to the request
* upon an out of memory event.
*
- * @var ?callable<?\Illuminate\Http\Response>
+ * @var ?callable(): ?Response
*/
protected $onOutOfMemory = null;
/**
* Report or log an exception.
*
- * @param \Throwable $exception
- *
- * @throws \Throwable
+ * @param Throwable $exception
*
* @return void
+ *@throws Throwable
+ *
*/
public function report(Throwable $exception)
{
/**
* Render an exception into an HTTP response.
*
- * @param \Illuminate\Http\Request $request
- * @param Exception $e
- *
- * @return \Illuminate\Http\Response
+ * @param Request $request
*/
- public function render($request, Throwable $e)
+ public function render($request, Throwable $e): SymfonyResponse
{
if ($e instanceof FatalError && str_contains($e->getMessage(), 'bytes exhausted (tried to allocate') && $this->onOutOfMemory) {
$response = call_user_func($this->onOutOfMemory);
* If the callable returns a response, this response will be returned
* to the request upon error.
*/
- public function prepareForOutOfMemory(callable $onOutOfMemory)
+ public function prepareForOutOfMemory(callable $onOutOfMemory): void
{
$this->onOutOfMemory = $onOutOfMemory;
}
/**
* Forget the current out of memory handler, if existing.
*/
- public function forgetOutOfMemoryHandler()
+ public function forgetOutOfMemoryHandler(): void
{
$this->onOutOfMemory = null;
}
/**
* Convert an authentication exception into an unauthenticated response.
*
- * @param \Illuminate\Http\Request $request
- * @param \Illuminate\Auth\AuthenticationException $exception
- *
- * @return \Illuminate\Http\Response
+ * @param Request $request
*/
- protected function unauthenticated($request, AuthenticationException $exception)
+ protected function unauthenticated($request, AuthenticationException $exception): SymfonyResponse
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
/**
* Convert a validation exception into a JSON response.
*
- * @param \Illuminate\Http\Request $request
- * @param \Illuminate\Validation\ValidationException $exception
- *
- * @return \Illuminate\Http\JsonResponse
+ * @param Request $request
*/
- protected function invalidJson($request, ValidationException $exception)
+ protected function invalidJson($request, ValidationException $exception): JsonResponse
{
return response()->json($exception->errors(), $exception->status);
}