Skip to content

Lower all logs to level DEBUG #1

@lucasmilhoranca-ipag

Description

@lucasmilhoranca-ipag
 Kubinyete\TemplateSdkPhp\Core\Client;

 public function request(
        string $method,
        string $url,
        $body,
        array $query = [],
        array $header = [],
        ?SerializerInterface $inputSerializer = null,
        ?SerializerInterface $outputSerializer = null
    ): Response {
        $requestId = $this->incrementRequestCounter();

        $outputSerializer ??= $this->defaultSerializer;
        $inputSerializer ??= $this->defaultSerializer;

        if ($inputSerializer) {
            $header['Content-Type'] = $header['Content-Type'] ?? $inputSerializer->getContentType();
        }

        if ($outputSerializer) {
            $header['Accept'] = $header['Accept'] ?? $outputSerializer->getContentType();
        }

        $this->logger->debug("({$requestId}) {$method} {$url} : Sending request", ['body' => $body, 'query' => $query, 'header' => $header]);

        try {
            $response = $this->httpClient->request(
                $method,
                $url,
                // @NOTE:
                // We are not using our custom serializer from args
                // because it easier for an external user to send an alternative body encoded
                // with another serialization method (Ex: XML) as an string instead of
                // assuming that the response from the current endpoint is also expecting
                // to receive XML data.
                $this->serialize($body, $inputSerializer),
                $query,
                $header
            );

            $response = Response::from($response);
            $response->setSerializer($outputSerializer);

            $this->logger->debug("({$requestId}) {$method} {$url} : Read successful", ['response' => $response->getBody()]);
            return $this->responseReceived($response) ?? $response;
        } catch (HttpException $e) {
            $response = $e->getResponse();
             // here
            $this->logger->debug("({$requestId}) {$method} {$url} : Read failed with status code {$e->getStatusCode()} {$e->getStatusMessage()}", ['exception' => strval($e), 'response' => $response ? $response->getBody() : null]);

            if ($response) {
                $response->setSerializer($outputSerializer);
            }

            $this->exceptionThrown($e);
        } catch (Throwable $e) {
            // here
            $this->logger->debug("({$requestId}) {$method} {$url} : Read failed with unhandled exception", ['exception' => strval($e)]);
            $this->exceptionThrown($e);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions