Skip to content

Commit

Permalink
fix: add actionable errors for GCE long running operations
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed May 19, 2023
1 parent 6acb3a9 commit 0e3f9bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions google/api_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ def __init__(self, message, errors=(), details=(), response=None, error_info=Non
self._error_info = error_info

def __str__(self):
error_msg = "{} {}".format(self.code, self.message)
if self.details:
return "{} {} {}".format(self.code, self.message, self.details)
error_msg = "{} {}".format(error_msg, self.details)
else:
return "{} {}".format(self.code, self.message)
if self.errors:
errors = [
f"{error.code}: {error.message}"
for error in self.errors
if hasattr(error, "code") and hasattr(error, "message")
]
if len(errors) > 0:
error_msg = "".join(error_msg, "\n".join(errors))
return error_msg

@property
def reason(self):
Expand Down
4 changes: 4 additions & 0 deletions google/api_core/extended_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ def _handle_refreshed_operation(self):
return

if self.error_code and self.error_message:
errors = []
if hasattr(self, "error") and hasattr(self.error, "errors"):
errors = self.error.errors
exception = exceptions.from_http_status(
status_code=self.error_code,
message=self.error_message,
response=self._extended_operation,
errors=errors,
)
self.set_exception(exception)
elif self.error_code or self.error_message:
Expand Down

0 comments on commit 0e3f9bd

Please sign in to comment.