Skip to content

Commit

Permalink
Added error handling for bad project ID provided
Browse files Browse the repository at this point in the history
  • Loading branch information
duckduckgrayduck committed Feb 15, 2024
1 parent 8c8d0c7 commit 38adac3
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Upload transcribed audio files to DocumentCloud using Whisper
"""
import os
import json
import shutil
import sys
from subprocess import call, CalledProcessError
Expand Down Expand Up @@ -172,13 +173,28 @@ def main(self):

with open(f"{basename}.txt", "w+", encoding="utf-8") as file_:
format_segments(result, file_)
try:
self.client.documents.upload(
f"{basename}.txt",
original_extension="txt",
access=access_level,
**kwargs,
)
except APIError as e:
error_data = json.loads(e.response)
if "projects" in error_data:
self.set_message(
"Please check that you provided either a"
"valid project ID or left it completely blank. Try again."
)
sys.exit(0)
else:
self.set_message(
"API error reached, contact info@documentcloud.org for support"
)
print(e)
sys.exit(1)

self.client.documents.upload(
f"{basename}.txt",
original_extension="txt",
access=access_level,
**kwargs,
)
successes += 1

sfiles = "file" if successes == 1 else "files"
Expand Down

0 comments on commit 38adac3

Please sign in to comment.