Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/__init__.py
Show First 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | def raise_for_status(self, response) -> None: | ||||
exception = None | exception = None | ||||
# TODO: only old servers send pickled error; stop trying to unpickle | # TODO: only old servers send pickled error; stop trying to unpickle | ||||
# after they are all upgraded | # after they are all upgraded | ||||
try: | try: | ||||
if status_class == 4: | if status_class == 4: | ||||
data = self._decode_response(response, check_status=False) | data = self._decode_response(response, check_status=False) | ||||
if isinstance(data, dict): | if isinstance(data, dict): | ||||
# TODO: remove "exception" key check once all servers | |||||
# are using new schema | |||||
exc_data = data["exception"] if "exception" in data else data | |||||
for exc_type in self.reraise_exceptions: | for exc_type in self.reraise_exceptions: | ||||
if exc_type.__name__ == data["type"]: | if exc_type.__name__ == exc_data["type"]: | ||||
exception = exc_type(*data["args"]) | exception = exc_type(*exc_data["args"]) | ||||
break | break | ||||
else: | else: | ||||
# old dict encoded exception schema | exception = RemoteException(payload=exc_data, response=response) | ||||
# TODO: Remove that code once all servers are using new schema | |||||
if "exception" in data: | |||||
exception = RemoteException( | |||||
payload=data["exception"], response=response | |||||
) | |||||
else: | |||||
exception = RemoteException(payload=data, response=response) | |||||
else: | else: | ||||
exception = pickle.loads(data) | exception = pickle.loads(data) | ||||
elif status_class == 5: | elif status_class == 5: | ||||
data = self._decode_response(response, check_status=False) | data = self._decode_response(response, check_status=False) | ||||
if "exception_pickled" in data: | if "exception_pickled" in data: | ||||
exception = pickle.loads(data["exception_pickled"]) | exception = pickle.loads(data["exception_pickled"]) | ||||
# old dict encoded exception schema | |||||
# TODO: Remove that code once all servers are using new schema | |||||
elif "exception" in data: | |||||
exception = RemoteException( | |||||
payload=data["exception"], response=response | |||||
) | |||||
else: | else: | ||||
exception = RemoteException(payload=data, response=response) | # TODO: remove "exception" key check once all servers | ||||
# are using new schema | |||||
exc_data = data["exception"] if "exception" in data else data | |||||
exception = RemoteException(payload=exc_data, response=response) | |||||
except (TypeError, pickle.UnpicklingError): | except (TypeError, pickle.UnpicklingError): | ||||
raise RemoteException(payload=data, response=response) | raise RemoteException(payload=data, response=response) | ||||
if exception: | if exception: | ||||
raise exception from None | raise exception from None | ||||
if status_class != 2: | if status_class != 2: | ||||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |