|
17 | 17 | async_to_streamed_response_wrapper, |
18 | 18 | ) |
19 | 19 | from ..._constants import DEFAULT_TIMEOUT |
20 | | -from ..._exceptions import APIStatusError |
| 20 | +from ..._exceptions import APIStatusError, APITimeoutError |
21 | 21 | from ...lib.polling import PollingConfig, poll_until |
22 | 22 | from ..._base_client import make_request_options |
23 | 23 | from ...types.devboxes import execution_retrieve_params, execution_execute_sync_params, execution_execute_async_params |
|
28 | 28 | __all__ = ["ExecutionsResource", "AsyncExecutionsResource"] |
29 | 29 |
|
30 | 30 |
|
| 31 | +def placeholder_execution_detail_view(devbox_id: str, execution_id: str) -> DevboxAsyncExecutionDetailView: |
| 32 | + return DevboxAsyncExecutionDetailView( |
| 33 | + devbox_id=devbox_id, |
| 34 | + execution_id=execution_id, |
| 35 | + status="queued", |
| 36 | + stdout="", |
| 37 | + stderr="", |
| 38 | + ) |
| 39 | + |
| 40 | + |
31 | 41 | class ExecutionsResource(SyncAPIResource): |
32 | 42 | @cached_property |
33 | 43 | def with_raw_response(self) -> ExecutionsResourceWithRawResponse: |
@@ -127,16 +137,12 @@ def wait_for_execution_status() -> DevboxAsyncExecutionDetailView: |
127 | 137 | ) |
128 | 138 |
|
129 | 139 | def handle_timeout_error(error: Exception) -> DevboxAsyncExecutionDetailView: |
130 | | - # Handle 408 timeout errors by returning current execution state to continue polling |
131 | | - if isinstance(error, APIStatusError) and error.response.status_code == 408: |
| 140 | + # Handle timeout errors by returning current execution state to continue polling |
| 141 | + if isinstance(error, APITimeoutError) or ( |
| 142 | + isinstance(error, APIStatusError) and error.response.status_code == 408 |
| 143 | + ): |
132 | 144 | # Return a placeholder result to continue polling |
133 | | - return DevboxAsyncExecutionDetailView( |
134 | | - devbox_id=devbox_id, |
135 | | - execution_id=execution_id, |
136 | | - status="queued", |
137 | | - stdout="", |
138 | | - stderr="", |
139 | | - ) |
| 145 | + return placeholder_execution_detail_view(devbox_id, execution_id) |
140 | 146 | else: |
141 | 147 | # Re-raise other errors to stop polling |
142 | 148 | raise error |
@@ -410,19 +416,13 @@ async def wait_for_execution_status() -> DevboxAsyncExecutionDetailView: |
410 | 416 | body={"statuses": ["completed"]}, |
411 | 417 | cast_to=DevboxAsyncExecutionDetailView, |
412 | 418 | ) |
413 | | - except APIStatusError as error: |
414 | | - if error.response.status_code == 408: |
415 | | - # Handle 408 timeout errors by returning current execution state to continue polling |
416 | | - return DevboxAsyncExecutionDetailView( |
417 | | - devbox_id=devbox_id, |
418 | | - execution_id=execution_id, |
419 | | - status="queued", |
420 | | - stdout="", |
421 | | - stderr="", |
422 | | - ) |
423 | | - else: |
424 | | - # Re-raise other errors to stop polling |
425 | | - raise |
| 419 | + except (APITimeoutError, APIStatusError) as error: |
| 420 | + # Handle timeout errors by returning placeholder to continue polling |
| 421 | + if isinstance(error, APITimeoutError) or error.response.status_code == 408: |
| 422 | + return placeholder_execution_detail_view(devbox_id, execution_id) |
| 423 | + |
| 424 | + # Re-raise other errors to stop polling |
| 425 | + raise |
426 | 426 |
|
427 | 427 | def is_done(execution: DevboxAsyncExecutionDetailView) -> bool: |
428 | 428 | return execution.status == "completed" |
|
0 commit comments