level; } public function getStatusCode(): int { return Response::HTTP_BAD_REQUEST; } /** * @return array */ public function getHeaders(): array { return []; } /** * Render the exception by redirecting the user back to the page that they came * from. If the request originated from an API hit, return the error in JSONAPI * spec format. */ public function render(Request $request): JsonResponse|RedirectResponse { if ($request->expectsJson() || $request->is('api/*')) { return response()->json(ApiErrorResponse::toArray($this), $this->getStatusCode(), $this->getHeaders()); } return back()->withInput(); } /** * Log the exception to the logs using the defined error level only if the previous * exception is set. */ public function report(): void { $previous = $this->getPrevious(); if (! $previous instanceof Throwable || ! Exceptions::shouldReport($previous)) { return; } $context = ['exception' => $previous]; match ($this->getErrorLevel()) { self::LEVEL_DEBUG => Log::debug($previous->getMessage(), $context), self::LEVEL_INFO => Log::info($previous->getMessage(), $context), self::LEVEL_WARNING => Log::warning($previous->getMessage(), $context), default => Log::error($previous->getMessage(), $context), }; } }