|
32 | 32 | from apify._proxy_configuration import ProxyConfiguration |
33 | 33 | from apify._utils import docs_group, docs_name, ensure_context, get_system_info, is_running_in_ipython |
34 | 34 | from apify._webhook import to_client_representations |
| 35 | +from apify.errors import map_client_errors |
35 | 36 | from apify.events import ApifyEventManager, EventManager, LocalEventManager |
36 | 37 | from apify.log import _configure_logging, logger |
37 | 38 | from apify.storage_clients import ApifyStorageClient, SmartApifyStorageClient |
@@ -936,17 +937,18 @@ async def start( |
936 | 937 | raise ValueError(f'Invalid timeout {timeout!r}: expected `None`, `"inherit"`, or a `timedelta`.') |
937 | 938 |
|
938 | 939 | actor_client = client.actor(actor_id) |
939 | | - return await actor_client.start( |
940 | | - run_input=run_input, |
941 | | - content_type=content_type, |
942 | | - build=build, |
943 | | - max_total_charge_usd=max_total_charge_usd, |
944 | | - restart_on_error=restart_on_error, |
945 | | - memory_mbytes=memory_mbytes, |
946 | | - run_timeout=actor_start_timeout, |
947 | | - force_permission_level=force_permission_level, |
948 | | - webhooks=to_client_representations(webhooks), |
949 | | - ) |
| 940 | + with map_client_errors(): |
| 941 | + return await actor_client.start( |
| 942 | + run_input=run_input, |
| 943 | + content_type=content_type, |
| 944 | + build=build, |
| 945 | + max_total_charge_usd=max_total_charge_usd, |
| 946 | + restart_on_error=restart_on_error, |
| 947 | + memory_mbytes=memory_mbytes, |
| 948 | + run_timeout=actor_start_timeout, |
| 949 | + force_permission_level=force_permission_level, |
| 950 | + webhooks=to_client_representations(webhooks), |
| 951 | + ) |
950 | 952 |
|
951 | 953 | @_ensure_context |
952 | 954 | async def abort( |
@@ -975,10 +977,11 @@ async def abort( |
975 | 977 | client = self.new_client(token=token) if token else self.apify_client |
976 | 978 | run_client = client.run(run_id) |
977 | 979 |
|
978 | | - if status_message: |
979 | | - await run_client.update(status_message=status_message) |
| 980 | + with map_client_errors(): |
| 981 | + if status_message: |
| 982 | + await run_client.update(status_message=status_message) |
980 | 983 |
|
981 | | - run = await run_client.abort(gracefully=gracefully) |
| 984 | + run = await run_client.abort(gracefully=gracefully) |
982 | 985 |
|
983 | 986 | if run is None: |
984 | 987 | raise RuntimeError(f'Failed to abort Actor run with ID "{run_id}".') |
@@ -1047,19 +1050,20 @@ async def call( |
1047 | 1050 | raise ValueError(f'Invalid timeout {timeout!r}: expected `None`, `"inherit"`, or a `timedelta`.') |
1048 | 1051 |
|
1049 | 1052 | actor_client = client.actor(actor_id) |
1050 | | - run = await actor_client.call( |
1051 | | - run_input=run_input, |
1052 | | - content_type=content_type, |
1053 | | - build=build, |
1054 | | - max_total_charge_usd=max_total_charge_usd, |
1055 | | - restart_on_error=restart_on_error, |
1056 | | - memory_mbytes=memory_mbytes, |
1057 | | - run_timeout=actor_call_timeout, |
1058 | | - force_permission_level=force_permission_level, |
1059 | | - webhooks=to_client_representations(webhooks), |
1060 | | - wait_duration=wait, |
1061 | | - logger=logger, |
1062 | | - ) |
| 1053 | + with map_client_errors(): |
| 1054 | + run = await actor_client.call( |
| 1055 | + run_input=run_input, |
| 1056 | + content_type=content_type, |
| 1057 | + build=build, |
| 1058 | + max_total_charge_usd=max_total_charge_usd, |
| 1059 | + restart_on_error=restart_on_error, |
| 1060 | + memory_mbytes=memory_mbytes, |
| 1061 | + run_timeout=actor_call_timeout, |
| 1062 | + force_permission_level=force_permission_level, |
| 1063 | + webhooks=to_client_representations(webhooks), |
| 1064 | + wait_duration=wait, |
| 1065 | + logger=logger, |
| 1066 | + ) |
1063 | 1067 |
|
1064 | 1068 | if run is None: |
1065 | 1069 | raise RuntimeError(f'Failed to call Actor with ID "{actor_id}".') |
@@ -1120,15 +1124,16 @@ async def call_task( |
1120 | 1124 | raise ValueError(f'Invalid timeout {timeout!r}: expected `None`, `"inherit"`, or a `timedelta`.') |
1121 | 1125 |
|
1122 | 1126 | task_client = client.task(task_id) |
1123 | | - run = await task_client.call( |
1124 | | - task_input=task_input, |
1125 | | - build=build, |
1126 | | - restart_on_error=restart_on_error, |
1127 | | - memory_mbytes=memory_mbytes, |
1128 | | - run_timeout=task_call_timeout, |
1129 | | - webhooks=to_client_representations(webhooks), |
1130 | | - wait_duration=wait, |
1131 | | - ) |
| 1127 | + with map_client_errors(): |
| 1128 | + run = await task_client.call( |
| 1129 | + task_input=task_input, |
| 1130 | + build=build, |
| 1131 | + restart_on_error=restart_on_error, |
| 1132 | + memory_mbytes=memory_mbytes, |
| 1133 | + run_timeout=task_call_timeout, |
| 1134 | + webhooks=to_client_representations(webhooks), |
| 1135 | + wait_duration=wait, |
| 1136 | + ) |
1132 | 1137 |
|
1133 | 1138 | if run is None: |
1134 | 1139 | raise RuntimeError(f'Failed to call Task with ID "{task_id}".') |
@@ -1171,12 +1176,13 @@ async def metamorph( |
1171 | 1176 | if not self.configuration.actor_run_id: |
1172 | 1177 | raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.') |
1173 | 1178 |
|
1174 | | - await self.apify_client.run(self.configuration.actor_run_id).metamorph( |
1175 | | - target_actor_id=target_actor_id, |
1176 | | - run_input=run_input, |
1177 | | - target_actor_build=target_actor_build, |
1178 | | - content_type=content_type, |
1179 | | - ) |
| 1179 | + with map_client_errors(): |
| 1180 | + await self.apify_client.run(self.configuration.actor_run_id).metamorph( |
| 1181 | + target_actor_id=target_actor_id, |
| 1182 | + run_input=run_input, |
| 1183 | + target_actor_build=target_actor_build, |
| 1184 | + content_type=content_type, |
| 1185 | + ) |
1180 | 1186 |
|
1181 | 1187 | if custom_after_sleep: |
1182 | 1188 | await asyncio.sleep(custom_after_sleep.total_seconds()) |
@@ -1242,7 +1248,8 @@ async def safe_dispatch(listener: Any, data: Any) -> None: |
1242 | 1248 | except TimeoutError: |
1243 | 1249 | self.log.warning('Pre-reboot event listeners did not finish within timeout; proceeding with reboot') |
1244 | 1250 |
|
1245 | | - await self.apify_client.run(self.configuration.actor_run_id).reboot() |
| 1251 | + with map_client_errors(): |
| 1252 | + await self.apify_client.run(self.configuration.actor_run_id).reboot() |
1246 | 1253 | except BaseException: |
1247 | 1254 | # Reset the flag so that a failed or cancelled reboot can be retried. |
1248 | 1255 | self._is_rebooting = False |
@@ -1283,17 +1290,18 @@ async def add_webhook(self, webhook: Webhook, *, idempotency_key: str | None = N |
1283 | 1290 | if not self.configuration.actor_run_id: |
1284 | 1291 | raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.') |
1285 | 1292 |
|
1286 | | - await self.apify_client.webhooks().create( |
1287 | | - actor_run_id=self.configuration.actor_run_id, |
1288 | | - event_types=webhook.event_types, |
1289 | | - request_url=webhook.request_url, |
1290 | | - payload_template=webhook.payload_template, |
1291 | | - headers_template=webhook.headers_template, |
1292 | | - ignore_ssl_errors=webhook.ignore_ssl_errors, |
1293 | | - do_not_retry=webhook.do_not_retry, |
1294 | | - idempotency_key=idempotency_key if idempotency_key is not None else webhook.idempotency_key, |
1295 | | - is_ad_hoc=True, |
1296 | | - ) |
| 1293 | + with map_client_errors(): |
| 1294 | + await self.apify_client.webhooks().create( |
| 1295 | + actor_run_id=self.configuration.actor_run_id, |
| 1296 | + event_types=webhook.event_types, |
| 1297 | + request_url=webhook.request_url, |
| 1298 | + payload_template=webhook.payload_template, |
| 1299 | + headers_template=webhook.headers_template, |
| 1300 | + ignore_ssl_errors=webhook.ignore_ssl_errors, |
| 1301 | + do_not_retry=webhook.do_not_retry, |
| 1302 | + idempotency_key=idempotency_key if idempotency_key is not None else webhook.idempotency_key, |
| 1303 | + is_ad_hoc=True, |
| 1304 | + ) |
1297 | 1305 |
|
1298 | 1306 | @_ensure_context |
1299 | 1307 | async def set_status_message( |
@@ -1321,10 +1329,11 @@ async def set_status_message( |
1321 | 1329 | raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.') |
1322 | 1330 |
|
1323 | 1331 | run_client = self.apify_client.run(self.configuration.actor_run_id) |
1324 | | - run = await run_client.update( |
1325 | | - status_message=status_message, |
1326 | | - is_status_message_terminal=is_terminal, |
1327 | | - ) |
| 1332 | + with map_client_errors(): |
| 1333 | + run = await run_client.update( |
| 1334 | + status_message=status_message, |
| 1335 | + is_status_message_terminal=is_terminal, |
| 1336 | + ) |
1328 | 1337 |
|
1329 | 1338 | if run is None: |
1330 | 1339 | raise RuntimeError( |
|
0 commit comments