-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved error message for json decoding
- Loading branch information
Showing
1 changed file
with
8 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,11 +54,11 @@ def extract_from_file(file_path: str, source_type: str, verbose: bool = False, a | |
data={'api_key': THEPIPE_API_KEY, 'ai_extraction': ai_extraction, 'text_only': text_only} | ||
) | ||
except Exception as e: | ||
raise ValueError(f"Failed to extract from file. This may mean our backend couldn't handle this request. Exception: {e}.") | ||
raise ValueError(f"Failed to extract from {file_path}. Exception: {e}.") | ||
try: | ||
response = response.json() | ||
except json.JSONDecodeError: | ||
raise ValueError(f"Our backend likely couldn't handle this request. This can happen with large content, very large files, or unsupported files") | ||
raise ValueError(f"Failed to extract from {file_path}. Response: {response}.") | ||
if 'error' in response: | ||
raise ValueError(f"{response['error']}") | ||
chunks = create_chunks_from_messages(response['messages']) | ||
|
@@ -186,7 +186,7 @@ def extract_pdf(file_path: str, ai_extraction: bool = False, text_only: bool = F | |
try: | ||
response_json = response.json() | ||
except json.JSONDecodeError: | ||
raise ValueError(f"Our backend likely couldn't handle this request. This can happen with large content such as videos, streams, or very large files/websites. See [email protected] for help.") | ||
raise ValueError(f"Our backend likely couldn't handle this request. This can happen with large content such as videos, streams, or very large files/websites. Re") | ||
if 'error' in response_json: | ||
raise ValueError(f"{response_json['error']}") | ||
messages = response_json['messages'] | ||
|
@@ -248,9 +248,13 @@ def extract_url(url: str, text_only: bool = False, local: bool = True) -> List[C | |
response = requests.post( | ||
url=API_URL, | ||
data={'url': url, 'api_key': THEPIPE_API_KEY, 'text_only': text_only} | ||
).json() | ||
) | ||
except Exception as e: | ||
raise ValueError(f"Failed to extract from URL. This may mean our backend couldn't handle this request. Exception: {e}.") | ||
try: | ||
response = response.json() | ||
except json.JSONDecodeError: | ||
raise ValueError(f"Failed to extract from URL. Response: {response}.") | ||
if 'error' in response: | ||
raise ValueError(f"{response['error']}") | ||
chunks = create_chunks_from_messages(response['messages']) | ||
|