Skip to content

Commit

Permalink
better-error-handling-no-credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielsoltz committed Mar 17, 2024
1 parent 7328725 commit 197057b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/context/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,20 @@ def get_account_organizations(self):
except ClientError as err:
organizations = False
if not err.response["Error"]["Code"] == "AWSOrganizationsNotInUseException":
self.logger.warning(
self.logger.error(
"Failed to describe_organization: %s, for resource: %s - %s",
self.resource_account_id,
self.resource_arn,
err,
)
except Exception as err:
organizations = False
self.logger.error(
"Failed to describe_organization: %s, for resource: %s - %s",
self.resource_account_id,
self.resource_arn,
err,
)
return organizations

def get_account_organizations_details(self):
Expand Down Expand Up @@ -410,21 +418,21 @@ def get_account_alternate_contact(self, alternate_contact_type="SECURITY"):
alternate_contact = account_client.get_alternate_contact(
AlternateContactType=alternate_contact_type
).get("AlternateContact")
except (NoCredentialsError, ClientError, EndpointConnectionError) as err:
except (ClientError, EndpointConnectionError) as err:
if err.response["Error"]["Code"] == "ResourceNotFoundException":
self.logger.info(
"No alternate contact found for account %s (%s) - %s",
self.resource_account_id,
self.resource_arn,
err,
)
else:
self.logger.warning(
"Failed to get_alternate_contact for account %s (%s) - %s",
self.resource_account_id,
self.resource_arn,
err,
)
except Exception as err:
self.logger.error(
"Failed to get_alternate_contact for account %s (%s) - %s",
self.resource_account_id,
self.resource_arn,
err,
)
return alternate_contact

def get_account_alias(self):
Expand Down

0 comments on commit 197057b

Please sign in to comment.