From d2a686b16532750d804287d8132fc6444bc4a111 Mon Sep 17 00:00:00 2001 From: Chad Norvell Date: Sun, 7 Jan 2024 08:31:09 -0800 Subject: [PATCH] community: Provide more actionable errors in the MathPix PDF loader (#15630) - **Description:** The `error_info['id']` can be cross-referenced with the MathPix API documentation to get very specific information about why an error occurred. --- .../community/langchain_community/document_loaders/pdf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/document_loaders/pdf.py b/libs/community/langchain_community/document_loaders/pdf.py index dc488834a6b..30615d3e7a3 100644 --- a/libs/community/langchain_community/document_loaders/pdf.py +++ b/libs/community/langchain_community/document_loaders/pdf.py @@ -462,9 +462,15 @@ class MathpixPDFLoader(BasePDFLoader): # This indicates an error with the request (e.g. auth problems) error = response_data.get("error", None) + error_info = response_data.get("error_info", None) if error is not None: - raise ValueError(f"Unable to retrieve PDF from Mathpix: {error}") + error_msg = f"Unable to retrieve PDF from Mathpix: {error}" + + if error_info is not None: + error_msg += f" ({error_info['id']})" + + raise ValueError(error_msg) status = response_data.get("status", None)