Skip to content

Commit

Permalink
Moved http status check up to catch more cases (#362)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Mercado <mamercad@gmail.com>
  • Loading branch information
jdrowell and mamercad authored May 22, 2024
1 parent 0dcb6a5 commit 06a4636
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions plugins/modules/digital_ocean_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,17 @@ def wait_action(self, droplet_id, desired_action_data):
json_data = response.json
status_code = response.status_code
message = json_data.get("message", "no error message")

# action and other fields may not be available in case of error, check first
# will catch Not Authorized due to restrictive Scopes
if status_code >= 400:
self.module.fail_json(
changed=False,
msg=DODroplet.failure_message["failed_to"].format(
"post", "action", status_code, message
),
)

action = json_data.get("action", None)
action_id = action.get("id", None)
action_status = action.get("status", None)
Expand All @@ -633,14 +644,6 @@ def wait_action(self, droplet_id, desired_action_data):
),
)

if status_code >= 400:
self.module.fail_json(
changed=False,
msg=DODroplet.failure_message["failed_to"].format(
"post", "action", status_code, message
),
)

# Keep checking till it is done or times out
self.wait_check_action(droplet_id, action_id)

Expand Down

0 comments on commit 06a4636

Please sign in to comment.