Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/__init__.py
Show First 20 Lines • Show All 310 Lines • ▼ Show 20 Lines | def raise_for_status(self, response) -> 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): | ||||
for exc_type in self.reraise_exceptions: | for exc_type in self.reraise_exceptions: | ||||
if exc_type.__name__ == data["exception"]["type"]: | if exc_type.__name__ == data["type"]: | ||||
exception = exc_type(*data["exception"]["args"]) | exception = exc_type(*data["args"]) | ||||
break | break | ||||
else: | # old dict encoded exception schema | ||||
# TODO: Remove that code once all servers are using new schema | |||||
if "exception" in data: | |||||
exception = RemoteException( | exception = RemoteException( | ||||
payload=data["exception"], response=response | payload=data["exception"], response=response | ||||
) | ) | ||||
else: | else: | ||||
exception = RemoteException(payload=data, response=response) | |||||
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"]) | ||||
else: | # old dict encoded exception schema | ||||
# TODO: Remove that code once all servers are using new schema | |||||
elif "exception" in data: | |||||
exception = RemoteException( | exception = RemoteException( | ||||
payload=data["exception"], response=response | payload=data["exception"], response=response | ||||
) | ) | ||||
else: | |||||
exception = RemoteException(payload=data, response=response) | |||||
vlorentz: you should add `elif "exception" in data: exception = RemoteException(payload=data["exception"]… | |||||
Done Inline ActionsAck, will update. anlambert: Ack, will update. | |||||
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 |
you should add elif "exception" in data: exception = RemoteException(payload=data["exception"], response=response), so we can upgrade clients first, then servers, without shutting everything down.
Then we can remove them.