# Buggy code
def create_block_storage(self):
    volume_name = self.get_key_or_fail("volume_name")
    snapshot_id = self.module.params["snapshot_id"]
    if snapshot_id:
        self.module.params["block_size"] = None
        self.module.params["region"] = None
        block_size = None
        region = None
    else:
        block_size = self.get_key_or_fail("block_size")
        region = self.get_key_or_fail("region")
    description = self.module.params["description"]
    data = {
        "size_gigabytes": block_size,
        "name": volume_name,
        "description": description,
        "region": region,
        "snapshot_id": snapshot_id,
    }
    response = self.rest.post("volumes", data=data)
    status = response.status_code
    json = response.json
    if status == 201:
        self.module.exit_json(changed=True, id=json["volume"]["id"])
    elif status == 409 and json["id"] == "already_exists":
        self.module.exit_json(changed=False)
    else:
        raise DOBlockStorageException(json["message"])


# Traceback (KeyError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/p5/m7r6p0795rg49s603ry355780000gn/T/ansible_cFlE1K/ansible_module_digital_ocean_block_storage.py", line 285, in main
handle_request(module)
File "/var/folders/p5/m7r6p0795rg49s603ry355780000gn/T/ansible_cFlE1K/ansible_module_digital_ocean_block_storage.py", line 259, in handle_request
block_storage.create_block_storage()
File "/var/folders/p5/m7r6p0795rg49s603ry355780000gn/T/ansible_cFlE1K/ansible_module_digital_ocean_block_storage.py", line 213, in create_block_storage
raise DOBlockStorageException(json['message'])
KeyError: 'message'

failed: [localhost] (item={u'owner': u'ubuntu', u'fstype': u'xfs', u'mount_name': u'backup', u'name': u'archive-staging-backup3', u'size': 100}) => {
"changed": false,
"invocation": {
"module_args": {
"api_token": null,
"block_size": 100,
"command": "create",
"description": null,
"droplet_id": null,
"region": "sfo2",
"snapshot_id": null,
"state": "present",
"timeout": 10,
"volume_name": "archive-staging-backup3"
}
},
"item": {
"fstype": "xfs",
"mount_name": "backup",
"name": "archive-staging-backup3",
"owner": "ubuntu",
"size": 100
},
"msg": "Unable to load message"
}

# Fixed code
def create_block_storage(self):
    volume_name = self.get_key_or_fail("volume_name")
    snapshot_id = self.module.params["snapshot_id"]
    if snapshot_id:
        self.module.params["block_size"] = None
        self.module.params["region"] = None
        block_size = None
        region = None
    else:
        block_size = self.get_key_or_fail("block_size")
        region = self.get_key_or_fail("region")
    description = self.module.params["description"]
    data = {
        "size_gigabytes": block_size,
        "name": volume_name,
        "description": description,
        "region": region,
        "snapshot_id": snapshot_id,
    }
    response = self.rest.post("volumes", data=data)
    status = response.status_code
    json = response.json
    if status == 201:
        self.module.exit_json(changed=True, id=json["volume"]["id"])
    elif status == 409 and json["id"] == "conflict":
        self.module.exit_json(changed=False)
    else:
        raise DOBlockStorageException(json["message"])