public function formatDetailed(
        RequestInterface $request,
        ResponseInterface &$response = null,
        Exception &$error = null
    ) {
        $needRewind = $this->shouldLogResponsePayload
            && !is_null($response) && !is_null($response->getBody());
        // Create a new response with its body as a rewindable caching stream.
        // This is needed when we want to both log the response body
        // and use it in other cases, e.g. creating an exception with this
        // response body, reading the content of the downloaded report.
        if ($needRewind && !$response->getBody()->isSeekable()) {
            $response =
                $response->withBody(new CachingStream($response->getBody()));

            if (!is_null($error)) {
                // Creates a new RequestException with the response whose stream
                // can be rewound.
                $error = RequestException::create(
                    $request,
                    $response,
                    $error
                );
            }
        }

        $detailedLog =
            $this->scrubAndFormatDetailedMessage($request, $response, $error);

        // Rewind the response stream so it can be used again, e.g. reading
        // the content of the downloaded report.
        if ($needRewind) {
            \GuzzleHttp\Psr7\rewind_body($response);
        }

        return $detailedLog;
    }