Skip to content

Handling of HTTP error messages #47

@aSauerwein

Description

@aSauerwein

Some failed request do not return any body element resulting in a unclear error message

For example an API Request to an intersight instance with self signed certs results return a {"changed": false, "msg": "API error: 'body' "}

A request to a non existent domain "bogus.intersight.com" also returns a:
{"changed": false, "msg": "API error: 'body' "}

The problematic code is at intersight.py 186ff

        try:
            response, info = self.intersight_call(**options)
            if not re.match(r'2..', str(info['status'])):
                raise RuntimeError(info['status'], info['msg'], info['body'])
        except Exception as e:
            self.module.fail_json(msg="API error: %s " % str(e))

Those 2 Errors do not return a "body" value => resulting in a KeyError.

A possible fix would be to exclude the "info['body']" from the RuntimeError statement or use info.get('body', '') instead.

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