private function handleErrors($response)
    {
        $json = json_decode($response->getBody());

        if ($json === null) {
            $msg = "Malformed response received from server";
            throw new Exception\MalformedResponseException($msg, $response);
        }

        if ($response->getStatusCode() < 400) {
            return null;
        }

        $error = $json->error;
        $exception_class = (string) ApiException::getErrorForType($error->type);
        $exception_class = 'GoCardlessPro\\Core\\Exception\\' . $exception_class;

        $api_response = new ApiResponse($response);
        throw new $exception_class($api_response);
    }