private function throwExceptionIfRequestRequiresAuthenticationOrReturnResponse(
        string $method,
        Request $request,
        Response $response
    ): Response {
        if ($response->statusCode() === Response::FORBIDDEN) {
            throw new AuthenticationRequiredException(
                sprintf(
                    'Request to "%s %s" requires authentication."',
                    $method,
                    $request->url()
                )
            );
        }

        return $response;
    }