def parse_error()

in libcloud/compute/drivers/ec2.py [0:0]


    def parse_error(self):
        err_list = []
        # Okay, so for Eucalyptus, you can get a 403, with no body,
        # if you are using the wrong user/password.
        msg = "Failure: 403 Forbidden"
        if self.status == 403 and self.body[: len(msg)] == msg:
            raise InvalidCredsError(msg)

        try:
            body = ET.XML(self.body)
        except Exception:
            raise MalformedResponseError(
                "Failed to parse XML", body=self.body, driver=EC2NodeDriver
            )

        for err in body.findall("Errors/Error"):
            code, message = list(err)
            err_list.append("{}: {}".format(code.text, message.text))
            if code.text == "InvalidClientTokenId":
                raise InvalidCredsError(err_list[-1])
            if code.text == "SignatureDoesNotMatch":
                raise InvalidCredsError(err_list[-1])
            if code.text == "AuthFailure":
                raise InvalidCredsError(err_list[-1])
            if code.text == "OptInRequired":
                raise InvalidCredsError(err_list[-1])
            if code.text == "IdempotentParameterMismatch":
                raise IdempotentParamError(err_list[-1])
            if code.text == "InvalidKeyPair.NotFound":
                # TODO: Use connection context instead
                match = re.match(r".*\'(.+?)\'.*", message.text)

                if match:
                    name = match.groups()[0]
                else:
                    name = None

                raise KeyPairDoesNotExistError(name=name, driver=self.connection.driver)
        return "\n".join(err_list)