protected function handle(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        $httpException = new HttpException($statusCode, $response->getReasonPhrase());

        if (!in_array($statusCode, [400, 401, 403], true)) {
            throw $httpException;
        }

        $error = json_decode((string) $response->getBody(), true);

        if (isset($error['ErrorMessage'])) {
            throw new ApiException($error['ErrorMessage'], $httpException);
        }

        $errorMessages = [];
        foreach ($error['Messages'] as $message) {
            if ('error' !== $message['Status']) {
                continue;
            }

            foreach ($message['Errors'] as $mailError) {
                $errorMessages[] = $mailError['ErrorMessage'];
            }
        }

        throw new ApiException(implode(', ', $errorMessages), $httpException);
    }
protected function handle(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        $httpException = new HttpException($statusCode, $response->getReasonPhrase());

        if (!in_array($statusCode, [400, 401, 403], true)) {
            throw $httpException;
        }

        $error = json_decode((string) $response->getBody(), true);

        if (isset($error['ErrorMessage'])) {
            throw new ApiException($error['ErrorMessage'], $httpException);
        }

        $errorMessages = [];
        foreach ($error['Messages'] as $message) {
            if ('error' !== $message['Status']) {
                continue;
            }

            foreach ($message['Errors'] as $mailError) {
                $errorMessages[] = $mailError['ErrorMessage'];
            }
        }

        throw new ApiException(implode(', ', $errorMessages), $httpException);
    }
{@inheritdoc}