Skip to content

Expose ClientException to api callers #25

@jontro

Description

@jontro

The following code in makeRequest will discard the error information in a call

  private function makeRequest($resource, $arguments, $method)
    {
        try {
            $options = $this->getOptions($method, $arguments);
            $response = $this->client->{$method}($this->endpoint . $resource, $options);

            $collection = new Collection(
                json_decode($response->getBody())
            );

            if ($collection->count() == 1) {
                return $collection->collapse();
            }

            return $collection;
        } catch (ClientException $e) {
            throw new Exception($e->getResponse()->getBody());
        } catch (RequestException $e) {
            $response = $e->getResponse();

            if ($response instanceof ResponseInterface) {
                throw new Exception($e->getResponse()->getBody());
            }

            throw new Exception($e->getMessage());
        }
    }

Since you discard the info that ClientException contains we cannot see what kind of Error mailchimp throws. For instance we need to create a customer if it does not exist, which we need to check if the response status is 404.

The PUT method is not enough here since it will throw if the email has changed.

Is it possible to expose the raw ClientException here instead of discarding it (i.e. throw $e) or what is the reasoning about doing this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions