| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import logging |
| 4 |
|
| 5 |
from globus_sdk import exc |
| 6 |
|
| 7 |
log = logging.getLogger(__name__) |
| 8 |
|
| 9 |
|
| 10 |
class AuthAPIError(exc.GlobusAPIError): |
| 11 |
""" |
| 12 |
Error class for the API components of Globus Auth. |
| 13 |
""" |
| 14 |
|
| 15 |
def _post_parse_hook(self) -> bool: |
| 16 |
# if there was only one error ID set in the response, use that as the request_id |
| 17 |
# this allows for some errors to omit the 'id': |
| 18 |
# |
| 19 |
# errors=[{"id": "foo"}, {}] |
| 20 |
# |
| 21 |
# or for all errors to have the same 'id': |
| 22 |
# |
| 23 |
# errors=[{"id": "foo"}, {"id": "foo"}] |
| 24 |
# |
| 25 |
# but not for errors to have mixed/different 'id' values: |
| 26 |
# |
| 27 |
# errors=[{"id": "foo"}, {"id": "bar"}] |
| 28 |
|
| 29 |
# step 1, collect error IDs |
| 30 |
error_ids = {suberror.get("id") for suberror in self.errors} |
| 31 |
# step 2, remove `None` from any sub-errors which did not set error_id or |
| 32 |
# explicitly set it to null |
| 33 |
error_ids.discard(None) |
| 34 |
# step 3, check if there was exactly one error ID and it was a string |
| 35 |
if len(error_ids) == 1: |
| 36 |
maybe_error_id = error_ids.pop() |
| 37 |
if isinstance(maybe_error_id, str): |
| 38 |
self.request_id = maybe_error_id |
| 39 |
|
| 40 |
return True |