Closed lukeocodes closed 5 months ago
@DamienDeepgram curious about this. Was an error event listener set up at the time this errored?
For e.g.
const dgConnection = deepgram.listen.live({ model: "nova" });
dgConnection.on(LiveTranscriptionEvents.Open, () => {
dgConnection.on(LiveTranscriptionEvents.Transcript, (data) => {
console.log(data);
});
dgConnection.on(LiveTranscriptionEvents.Error, (err) => {
console.error(err);
});
});
I've been reading a bit about this. It appears that (despite what you and I are both seeing) neither object throws an error?? The docs say it won't throw, it will only ever emit an error event. I don't get an error event, but I do see an uncaught exception.
:notlikethis:
Further reading, I realise now our websocket library is using a custom event when a connection handshake errors with a 404. We should add a listener for this and expose it to the users.
@DamienDeepgram curious about this. Was an error event listener set up at the time this errored?
For e.g.
const dgConnection = deepgram.listen.live({ model: "nova" }); dgConnection.on(LiveTranscriptionEvents.Open, () => { dgConnection.on(LiveTranscriptionEvents.Transcript, (data) => { console.log(data); }); dgConnection.on(LiveTranscriptionEvents.Error, (err) => { console.error(err); }); });
I was using the node-live sample in this repo here: https://github.com/deepgram/deepgram-js-sdk/blob/main/examples/node-live/index.js
It looks like that does not handle the errors.
So if I add the missing error handler this would catch there errors automatically nice.
I added a PR to add in the error handling
Hi dear all,
Allow me to re-open this issue as I believe it is still present in the Deepgram JS SDK - after a good amount of debugging the issue. It is easy reproducible using the server implementation here - https://github.com/deepgram-devs/node-live-example/blob/main/server.js
It turned out that my API key has expired - however, this is not the root cause of the issue. If attempting to connect to the Deepgram WSS API directly I’ve received the correct error - 401 Unauthorised and the connection was denied. The SDK does not handle the 401 Unauthorised event properly perhaps because another error is thrown in the middle of the whole process. The error is the same as reported in the beginning of this issue.
Environment:
Steps to Reproduce:
Get yourself an expired API key for Deepgram
Clone the aforementioned repo and put your API key
Run the server from the sample app
Connect to your server at localhost (via a client or a tool)
This will trigger the Node server implementation to try to connect to the Deepgram API
An error is thrown unexpectedly from inside the SDK:
node:events:505
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]
// omitted for brevity
(OPTIONAL) If you have correctly attached the LiveTranscriptionEvent.Close
listener (not inside of the event handler for LiveTranscriptionEvents.Open
but on the main level) you will also receive the event handled by the SDK that correctly understood the connection was closed:
{
"type":"close",
"isTrusted":false,
"_yaeti":true,
"code":1006,
"reason":"connection failed",
"wasClean":false,
"target":{
"_listeners":{
},
"_url":"wss://api.deepgram.com/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true",
"_readyState":3,
"_extensions":"",
"_bufferedAmount":0,
"_binaryType":"arraybuffer",
"_client":{
"_events":{
},
"_eventsCount":0,
"config":{
"maxReceivedFrameSize":1048576,
"maxReceivedMessageSize":8388608,
"fragmentOutgoingMessages":true,
"fragmentationThreshold":16384,
"webSocketVersion":13,
"assembleFragments":true,
"disableNagleAlgorithm":true,
"closeTimeout":5000,
"tlsOptions":{
}
},
"_req":null,
"protocols":[
....
],
"url":{
"protocol":"wss:",
"slashes":true,
"auth":null,
"host":"api.deepgram.com",
"port":"443",
"hostname":"api.deepgram.com",
"hash":null,
"search":"?smart_format=true&model=nova-2&language=fr&interim_results=true",
"query":"smart_format=true&model=nova-2&language=fr&interim_results=true",
"pathname":"/v1/listen",
"path":"/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true",
"href":"wss://api.deepgram.com/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true"
},
"secure":true,
"base64nonce":"vKmLdRFpuL3GyGm4p9dHJw=="
}
},
"cancelable":true
}
Further info:
When connecting via Postman directly to the WSS API - wss://api.deepgram.com/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true
and using the expired token in the Authorization header I receive the expected error - 401 Unauthorised.
Expected behaviour:
LiveTranscriptionEvent.Error
event is called.I hope this helps improving the SDK or someone stuck like me in debugging the error.
Thank you for the well-thought and architected SDK.
Hi dear all,
Allow me to re-open this issue as I believe it is still present in the Deepgram JS SDK - after a good amount of debugging the issue. It is easy reproducible using the server implementation here - https://github.com/deepgram-devs/node-live-example/blob/main/server.js
It turned out that my API key has expired - however, this is not the root cause of the issue. If attempting to connect to the Deepgram WSS API directly I’ve received the correct error - 401 Unauthorised and the connection was denied. The SDK does not handle the 401 Unauthorised event properly perhaps because another error is thrown in the middle of the whole process. The error is the same as reported in the beginning of this issue.
Environment:
- Deepgram JS SDK 3.3.3
- Node.js v20.9.0
Steps to Reproduce:
- Get yourself an expired API key for Deepgram
- Clone the aforementioned repo and put your API key
- Run the server from the sample app
- Connect to your server at localhost (via a client or a tool)
- This will trigger the Node server implementation to try to connect to the Deepgram API
- An error is thrown unexpectedly from inside the SDK:
node:events:505 throw err; // Unhandled 'error' event ^ Error [ERR_UNHANDLED_ERROR] // omitted for brevity
- (OPTIONAL) If you have correctly attached the
LiveTranscriptionEvent.Close
listener (not inside of the event handler forLiveTranscriptionEvents.Open
but on the main level) you will also receive the event handled by the SDK that correctly understood the connection was closed:{ "type":"close", "isTrusted":false, "_yaeti":true, "code":1006, "reason":"connection failed", "wasClean":false, "target":{ "_listeners":{ }, "_url":"wss://api.deepgram.com/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true", "_readyState":3, "_extensions":"", "_bufferedAmount":0, "_binaryType":"arraybuffer", "_client":{ "_events":{ }, "_eventsCount":0, "config":{ "maxReceivedFrameSize":1048576, "maxReceivedMessageSize":8388608, "fragmentOutgoingMessages":true, "fragmentationThreshold":16384, "webSocketVersion":13, "assembleFragments":true, "disableNagleAlgorithm":true, "closeTimeout":5000, "tlsOptions":{ } }, "_req":null, "protocols":[ .... ], "url":{ "protocol":"wss:", "slashes":true, "auth":null, "host":"api.deepgram.com", "port":"443", "hostname":"api.deepgram.com", "hash":null, "search":"?smart_format=true&model=nova-2&language=fr&interim_results=true", "query":"smart_format=true&model=nova-2&language=fr&interim_results=true", "pathname":"/v1/listen", "path":"/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true", "href":"wss://api.deepgram.com/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true" }, "secure":true, "base64nonce":"vKmLdRFpuL3GyGm4p9dHJw==" } }, "cancelable":true }
Further info:
When connecting via Postman directly to the WSS API -
wss://api.deepgram.com/v1/listen?smart_format=true&model=nova-2&language=fr&interim_results=true
and using the expired token in the Authorization header I receive the expected error - 401 Unauthorised.Expected behaviour:
- The Deepgram JS SDK doesn't throw an error - proper error handling is done in the SDK
- The
LiveTranscriptionEvent.Error
event is called.I hope this helps improving the SDK or someone stuck like me in debugging the error.
Thank you for the well-thought and architected SDK.
+1, having some problem. moved the error and close listeners at the same level as open listener, but still throws unhandled and crushes the app
Here is the full error I get
Here is what the emitted error contains