Skip to content

Commit 7cecf71

Browse files
committed
fix(python/sdk): update Realtime error codes and add check to avoid KeyError (#5854)
GitOrigin-RevId: b934ad7caebe865c546c45d944f109f524e630f2
1 parent bb65815 commit 7cecf71

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

assemblyai/transcriber.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,11 @@ def _handle_error(self, error: websockets.exceptions.ConnectionClosed) -> None:
13131313
- https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
13141314
- https://www.assemblyai.com/docs/Guides/real-time_streaming_transcription#closing-and-status-codes
13151315
"""
1316-
if error.code >= 4000 and error.code <= 4999:
1316+
if (
1317+
error.code >= 4000
1318+
and error.code <= 4999
1319+
and error.code in types.RealtimeErrorMapping
1320+
):
13171321
error_message = types.RealtimeErrorMapping[error.code]
13181322
else:
13191323
error_message = error.reason

assemblyai/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,9 +2278,11 @@ class RealtimeError(AssemblyAIError):
22782278
4031: "Session idle for too long",
22792279
4032: "Audio duration is too short",
22802280
4033: "Audio duration is too long",
2281+
4034: "Audio too small to transcode",
22812282
4100: "Endpoint received invalid JSON",
22822283
4101: "Endpoint received a message with an invalid schema",
22832284
4102: "This account has exceeded the number of allowed streams",
22842285
4103: "The session has been reconnected. This websocket is no longer valid.",
2286+
4104: "Could not parse word boost parameter",
22852287
1013: "Temporary server condition forced blocking client's request",
22862288
}

0 commit comments

Comments
 (0)