| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from globus_sdk._internal import guards |
| 4 |
from globus_sdk.exc import ErrorSubdocument, GlobusAPIError |
| 5 |
|
| 6 |
|
| 7 |
class FlowsAPIError(GlobusAPIError): |
| 8 |
""" |
| 9 |
Error class to represent error responses from Flows. |
| 10 |
""" |
| 11 |
|
| 12 |
def _parse_undefined_error_format(self) -> bool: |
| 13 |
""" |
| 14 |
Treat any top-level "error" key as an "array of size 1". |
| 15 |
Meaning that we'll see a single subdocument for data shaped like |
| 16 |
{ |
| 17 |
"error": { |
| 18 |
"foo": "bar" |
| 19 |
} |
| 20 |
} |
| 21 |
""" |
| 22 |
# if there is not a top-level 'error' key, no special behavior is defined |
| 23 |
# fall-back to the base class implementation |
| 24 |
if not isinstance(self._dict_data.get("error"), dict): |
| 25 |
return super()._parse_undefined_error_format() |
| 26 |
|
| 27 |
self.errors = [ErrorSubdocument(self._dict_data["error"])] |
| 28 |
self.code = self._extract_code_from_error_array(self.errors) |
| 29 |
|
| 30 |
details = self._dict_data["error"].get("detail") |
| 31 |
if guards.is_list_of(details, dict): |
| 32 |
self.messages = [ |
| 33 |
error_detail["msg"] |
| 34 |
for error_detail in details |
| 35 |
if isinstance(error_detail.get("msg"), str) |
| 36 |
] |
| 37 |
else: |
| 38 |
self.messages = self._extract_messages_from_error_array(self.errors) |
| 39 |
|
| 40 |
return True |