Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/__init__.py
Show First 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | def raise_for_status(self, response) -> None: | ||||
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["type"]: | if exc_type.__name__ == data["type"]: | ||||
exception = exc_type(*data["args"]) | exception = exc_type(*data["args"]) | ||||
break | break | ||||
else: | |||||
# old dict encoded exception schema | # old dict encoded exception schema | ||||
# TODO: Remove that code once all servers are using new schema | # TODO: Remove that code once all servers are using new schema | ||||
if "exception" in data: | 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) | 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 | # old dict encoded exception schema | ||||
▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines |