From 253ee614639403f01922d201206a4b7e5cbed545 Mon Sep 17 00:00:00 2001 From: Logan Date: Wed, 2 Oct 2024 18:57:46 -0600 Subject: [PATCH] improve error handling for jobs (#426) --- llama_parse/base.py | 11 ++++++++++- pyproject.toml | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/llama_parse/base.py b/llama_parse/base.py index cc05bcf..4ebf6eb 100644 --- a/llama_parse/base.py +++ b/llama_parse/base.py @@ -308,7 +308,8 @@ async def _get_job_result( continue # Allowed values "PENDING", "SUCCESS", "ERROR", "CANCELED" - status = result.json()["status"] + result_json = result.json() + status = result_json["status"] if status == "SUCCESS": parsed_result = await client.get(result_url, headers=headers) return parsed_result.json() @@ -320,6 +321,14 @@ async def _get_job_result( print(".", end="", flush=True) await asyncio.sleep(self.check_interval) + else: + error_code = result_json.get("error_code", "No error code found") + error_message = result_json.get( + "error_message", "No error message found" + ) + + exception_str = f"Job ID: {job_id} failed with status: {status}, Error code: {error_code}, Error message: {error_message}" + raise Exception(exception_str) async def _aload_data( self, diff --git a/pyproject.toml b/pyproject.toml index 570e3d9..27e92ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "llama-parse" -version = "0.5.6" +version = "0.5.7" description = "Parse files into RAG-Optimized formats." authors = ["Logan Markewich "] license = "MIT"