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.
This commit is contained in:
Chad Norvell 2024-01-07 08:31:09 -08:00 committed by GitHub
parent f0128dbcde
commit d2a686b165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)