77import httpx
88
99from ..._types import Body , Omit , Query , Headers , NotGiven , SequenceNotStr , omit , not_given
10+ from ..._exceptions import IndexingJobError
1011from ..._utils import maybe_transform , async_maybe_transform
1112from ..._compat import cached_property
1213from ..._resource import SyncAPIResource , AsyncAPIResource
@@ -301,7 +302,7 @@ def wait_for_completion(
301302
302303 Raises:
303304 TimeoutError: If the job doesn't complete within the specified timeout.
304- RuntimeError : If the job fails, errors, or is cancelled.
305+ IndexingJobError : If the job fails, errors, or is cancelled.
305306 """
306307 if not uuid :
307308 raise ValueError (f"Expected a non-empty value for `uuid` but received { uuid !r} " )
@@ -327,17 +328,27 @@ def wait_for_completion(
327328
328329 # Failure states
329330 if phase == "BATCH_JOB_PHASE_FAILED" :
330- raise RuntimeError (
331+ raise IndexingJobError (
331332 f"Indexing job { uuid } failed. "
332333 f"Total items indexed: { response .job .total_items_indexed } , "
333- f"Total items failed: { response .job .total_items_failed } "
334+ f"Total items failed: { response .job .total_items_failed } " ,
335+ uuid = uuid ,
336+ phase = phase ,
334337 )
335338
336339 if phase == "BATCH_JOB_PHASE_ERROR" :
337- raise RuntimeError (f"Indexing job { uuid } encountered an error" )
340+ raise IndexingJobError (
341+ f"Indexing job { uuid } encountered an error" ,
342+ uuid = uuid ,
343+ phase = phase ,
344+ )
338345
339346 if phase == "BATCH_JOB_PHASE_CANCELLED" :
340- raise RuntimeError (f"Indexing job { uuid } was cancelled" )
347+ raise IndexingJobError (
348+ f"Indexing job { uuid } was cancelled" ,
349+ uuid = uuid ,
350+ phase = phase ,
351+ )
341352
342353 # Still in progress (UNKNOWN, PENDING, or RUNNING)
343354 # Check timeout
@@ -623,7 +634,7 @@ async def wait_for_completion(
623634
624635 Raises:
625636 TimeoutError: If the job doesn't complete within the specified timeout.
626- RuntimeError : If the job fails, errors, or is cancelled.
637+ IndexingJobError : If the job fails, errors, or is cancelled.
627638 """
628639 if not uuid :
629640 raise ValueError (f"Expected a non-empty value for `uuid` but received { uuid !r} " )
@@ -649,17 +660,27 @@ async def wait_for_completion(
649660
650661 # Failure states
651662 if phase == "BATCH_JOB_PHASE_FAILED" :
652- raise RuntimeError (
663+ raise IndexingJobError (
653664 f"Indexing job { uuid } failed. "
654665 f"Total items indexed: { response .job .total_items_indexed } , "
655- f"Total items failed: { response .job .total_items_failed } "
666+ f"Total items failed: { response .job .total_items_failed } " ,
667+ uuid = uuid ,
668+ phase = phase ,
656669 )
657670
658671 if phase == "BATCH_JOB_PHASE_ERROR" :
659- raise RuntimeError (f"Indexing job { uuid } encountered an error" )
672+ raise IndexingJobError (
673+ f"Indexing job { uuid } encountered an error" ,
674+ uuid = uuid ,
675+ phase = phase ,
676+ )
660677
661678 if phase == "BATCH_JOB_PHASE_CANCELLED" :
662- raise RuntimeError (f"Indexing job { uuid } was cancelled" )
679+ raise IndexingJobError (
680+ f"Indexing job { uuid } was cancelled" ,
681+ uuid = uuid ,
682+ phase = phase ,
683+ )
663684
664685 # Still in progress (UNKNOWN, PENDING, or RUNNING)
665686 # Check timeout
0 commit comments