AssemblyAI / assemblyai-python-sdk

AssemblyAI's Official Python SDK
https://assemblyai.com
MIT License
135 stars 16 forks source link

Bad error handling in `Transcript.get_by_id` #77

Closed ploeber closed 1 month ago

ploeber commented 2 months ago

If either the API key is wrong or the transcript id is not available, there happens a bad error handling in get_by_id.

During handling of the above exception, another exception occurred.

The reason is that further down the line in wait_for_completion() we try to unpack a dictionary which then throws another exception.

Should be improved.

import assemblyai as aai
aai.settings.api_key = "some_key"

transcript = aai.Transcript.get_by_id("1234")
Traceback (most recent call last):
  File "/Users/patrick/projects/assemblyai-python-sdk/assemblyai/transcriber.py", line 79, in wait_for_completion
    self.transcript = api.get_transcript(
                      ^^^^^^^^^^^^^^^^^^^
  File "/Users/patrick/projects/assemblyai-python-sdk/assemblyai/api.py", line 61, in get_transcript
    raise types.TranscriptError(
assemblyai.types.TranscriptError: failed to retrieve transcript 1234: Authentication error, API token missing/invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/patrick/projects/assemblyai-python-sdk/ent-test.py", line 5, in <module>
    t = aai.Transcript.get_by_id("1234")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/patrick/projects/assemblyai-python-sdk/assemblyai/transcriber.py", line 255, in get_by_id
    return cls(transcript_id=transcript_id).wait_for_completion()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/patrick/projects/assemblyai-python-sdk/assemblyai/transcriber.py", line 218, in wait_for_completion
    self._impl.wait_for_completion()
  File "/Users/patrick/projects/assemblyai-python-sdk/assemblyai/transcriber.py", line 85, in wait_for_completion
    **self.transcript.dict(
      ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'dict'