Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Error : 429 / 402 #353

Open
Piyush-VO opened this issue Jan 7, 2025 · 0 comments
Open

Unhandled Error : 429 / 402 #353

Piyush-VO opened this issue Jan 7, 2025 · 0 comments

Comments

@Piyush-VO
Copy link

What is the current behavior?

In case of errors, like 429 / 402

  1. An unhandled error is thrown during the execution of the method.
  2. The SDK ceases to function, halting further processes dependent on it.
  3. The error prevents recovery without explicitly handling the exception.

Steps to reproduce

  1. Use an API key linked to an account with a balance of 0 or negative credits.
  2. Call the method deepgram.listen.live(config) with valid configuration parameters.
  3. Observe the error thrown by the SDK.

Expected behavior

The SDK should provide a handled error with clear messaging, allowing developers to take corrective action.

Please tell us about your environment

 Node.js v20.11.1

Other information

Response Sample

` node:events:509
throw err; // Unhandled 'error' event
^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (ErrorEvent {
[Symbol(kTarget)]: WebSocket {
_events: [Object: null prototype] {
open: [Function],
close: [Function],
error: [Function],
message: [Function]
},
_eventsCount: 4,
_maxListeners: undefined,
_binaryType: 'nodebuffer',
_closeCode: 1006,
_closeFrameReceived: false,
_closeFrameSent: false,
_closeMessage: ,
_closeTimer: null,
_errorEmitted: true,
_extensions: {},
_paused: false,
_protocol: '',
_readyState: 2,
_receiver: null,
_sender: null,
_socket: null,
_bufferedAmount: 0,
_isServer: false,
_redirects: 0,
_autoPong: true,
_url: 'wss://api.deepgram.com/v1/listen?version=latest&model=nova-2&encoding=mulaw&sample_rate=8000&endpointing=250&language=en&numerals=true&speech_final=true&punctuate=true&is_final=true&alternatives=1',
_req: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /v1/listen?version=latest&model=nova-2&encoding=mulaw&sample_rate=8000&endpointing=250&language=en&numerals=true&speech_final=true&punctuate=true&is_final=true&alternatives=1 HTTP/1.1\r\n' +
'Content-Type: application/json\r\n' +
'X-Client-Info: @deepgram/sdk; server; v3.9.0\r\n' +
'User-Agent: @deepgram/sdk/3.9.0 node/20.11.1\r\n' +
'Authorization: Token b30a80f8b77d4d7b1f7901e77a35227a09b49980\r\n' +
'Sec-WebSocket-Version: 13\r\n' +
'Sec-WebSocket-Key: Tua0z+aRzLzo2nVegBuXIg==\r\n' +
'Connection: Upgrade\r\n' +
'Upgrade: websocket\r\n' +
'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n' +
'Host: api.deepgram.com\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: undefined,
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
joinDuplicateHeaders: undefined,
path: '/v1/listen?version=latest&model=nova-2&encoding=mulaw&sample_rate=8000&endpointing=250&language=en&numerals=true&speech_final=true&punctuate=true&is_final=true&alternatives=1',
_ended: false,
res: [IncomingMessage],
aborted: true,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'api.deepgram.com',
protocol: 'https:',
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(errored)]: null,
[Symbol(kHighWaterMark)]: 16384,
[Symbol(kRejectNonStandardBodyWrites)]: false,
[Symbol(kUniqueHeaders)]: null,
[Symbol(kAborted)]: true,
[Symbol(kError)]: undefined
},
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
[Symbol(kType)]: 'error',
[Symbol(kError)]: Error: Unexpected server response: 402
at ClientRequest. (/Users/piyush/Documents/Code/Node/voice-socket/node_modules/ws/lib/websocket.js:913:7)
at ClientRequest.emit (node:events:518:28)
at HTTPParser.parserOnIncomingClient (node:_http_client:693:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:535:22)
at TLSSocket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23),
[Symbol(kMessage)]: 'Unexpected server response: 402'
})
at ListenLiveClient.emit (node:events:507:17)
at conn.onerror (/Users/piyush/Documents/Code/Node/voice-socket/node_modules/@deepgram/sdk/dist/main/packages/ListenLiveClient.js:51:22)
at callListener (/Users/piyush/Documents/Code/Node/voice-socket/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onError (/Users/piyush/Documents/Code/Node/voice-socket/node_modules/ws/lib/event-target.js:230:9)
at WebSocket.emit (node:events:518:28)
at emitErrorAndClose (/Users/piyush/Documents/Code/Node/voice-socket/node_modules/ws/lib/websocket.js:1041:13)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ERR_UNHANDLED_ERROR',
context: ErrorEvent {
[Symbol(kTarget)]: WebSocket {
_events: [Object: null prototype] {
open: [Function: onOpen] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function (anonymous)]
},
close: [Function: onClose] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function (anonymous)]
},
error: [Function: onError] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function (anonymous)]
},
message: [Function: onMessage] {
[Symbol(kIsForOnEventAttribute)]: true,
[Symbol(kListener)]: [Function (anonymous)]
}
},
_eventsCount: 4,
_maxListeners: undefined,
_binaryType: 'nodebuffer',
_closeCode: 1006,
_closeFrameReceived: false,
_closeFrameSent: false,
_closeMessage: Buffer(0) [Uint8Array] [],
_closeTimer: null,
_errorEmitted: true,
_extensions: {},
_paused: false,
_protocol: '',
_readyState: 2,
_receiver: null,
_sender: null,
_socket: null,
_bufferedAmount: 0,
_isServer: false,
_redirects: 0,
_autoPong: true,
_url: 'wss://api.deepgram.com/v1/listen?version=latest&model=nova-2&encoding=mulaw&sample_rate=8000&endpointing=250&language=en&numerals=true&speech_final=true&punctuate=true&is_final=true&alternatives=1',
_req: <ref *1> ClientRequest {
_events: [Object: null prototype] {
error: [Function (anonymous)],
response: [Function (anonymous)],
upgrade: [Function (anonymous)],
finish: [Function: requestOnFinish]
},
_eventsCount: 4,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: <ref *2> TLSSocket {
_tlsOptions: {
allowHalfOpen: undefined,
pipe: false,
secureContext: [SecureContext],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined,
enableTrace: undefined,
pskCallback: undefined,
highWaterMark: undefined,
onread: undefined,
signal: undefined
},
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'api.deepgram.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype] {
close: [Array],
end: [Function: onReadableStreamEnd],
error: [Function: socketErrorListener],
newListener: [Array],
connect: undefined,
secure: [Function: onConnectSecure],
data: undefined,
drain: undefined,
timeout: [Function: responseOnTimeout]
},
_eventsCount: 6,
connecting: false,
_hadError: false,
_parent: null,
_host: 'api.deepgram.com',
_closeAfterHandlingError: false,
_readableState: ReadableState {
highWaterMark: 16384,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 60563828
},
_writableState: WritableState {
highWaterMark: 16384,
length: 0,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 0,
bufferedIndex: 0,
pendingcb: 0,
[Symbol(kState)]: 17564020,
[Symbol(kBufferedValue)]: null,
[Symbol(kWriteCbValue)]: [Function: bound onFinish]
},
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular *1],
[Symbol(alpncallback)]: null,
[Symbol(res)]: TLSWrap {
_parent: [TCP],
_parentWrap: null,
_secureContext: [SecureContext],
reading: true,
onkeylog: [Function: onkeylog],
onhandshakestart: {},
onhandshakedone: [Function (anonymous)],
onocspresponse: [Function: onocspresponse],
onnewsession: [Function: onnewsessionclient],
onerror: [Function: onerror],
[Symbol(owner_symbol)]: [Circular *2]
},
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 1568,
[Symbol(kHandle)]: null,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: false,
[Symbol(kSetKeepAliveInitialDelay)]: 0,
[Symbol(kBytesRead)]: 704,
[Symbol(kBytesWritten)]: 607,
[Symbol(connect-options)]: {
rejectUnauthorized: true,
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
checkServerIdentity: [Function: checkServerIdentity],
minDHSize: 1024,
allowSynchronousEvents: true,
autoPong: true,
protocolVersion: 13,
maxPayload: 104857600,
skipUTF8Validation: false,
perMessageDeflate: true,
followRedirects: false,
maxRedirects: 10,
headers: [Object],
socketPath: undefined,
hostname: undefined,
protocol: undefined,
timeout: undefined,
method: 'GET',
host: 'api.deepgram.com',
path: undefined,
port: 443,
createConnection: [Function: tlsConnect],
defaultPort: 443,
_defaultAgent: [Agent],
servername: 'api.deepgram.com',
singleUse: true
}
},
_header: 'GET /v1/listen?version=latest&model=nova-2&encoding=mulaw&sample_rate=8000&endpointing=250&language=en&numerals=true&speech_final=true&punctuate=true&is_final=true&alternatives=1 HTTP/1.1\r\n' +
'Content-Type: application/json\r\n' +
'X-Client-Info: @deepgram/sdk; server; v3.9.0\r\n' +
'User-Agent: @deepgram/sdk/3.9.0 node/20.11.1\r\n' +
'Authorization: Token b30a80f8b77d4d7b1f7901e77a35227a09b49980\r\n' +
'Sec-WebSocket-Version: 13\r\n' +
'Sec-WebSocket-Key: Tua0z+aRzLzo2nVegBuXIg==\r\n' +
'Connection: Upgrade\r\n' +
'Upgrade: websocket\r\n' +
'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n' +
'Host: api.deepgram.com\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: undefined,
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
joinDuplicateHeaders: undefined,
path: '/v1/listen?version=latest&model=nova-2&encoding=mulaw&sample_rate=8000&endpointing=250&language=en&numerals=true&speech_final=true&punctuate=true&is_final=true&alternatives=1',
_ended: false,
res: IncomingMessage {
_events: {
close: undefined,
error: undefined,
data: undefined,
end: [Function: responseOnEnd],
readable: undefined
},
_readableState: ReadableState {
highWaterMark: 16384,
buffer: [],
bufferIndex: 0,
length: 0,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 60035852
},
_maxListeners: undefined,
socket: <ref *2> TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'api.deepgram.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 6,
connecting: false,
_hadError: false,
_parent: null,
_host: 'api.deepgram.com',
_closeAfterHandlingError: false,
_readableState: [ReadableState],
_writableState: [WritableState],
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular *1],
[Symbol(alpncallback)]: null,
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 1568,
[Symbol(kHandle)]: null,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: false,
[Symbol(kSetKeepAliveInitialDelay)]: 0,
[Symbol(kBytesRead)]: 704,
[Symbol(kBytesWritten)]: 607,
[Symbol(connect-options)]: [Object]
},
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: [
'content-type',
'application/json',
'dg-error',
'Project does not have enough credits for an ASR request and does not have an overage agreement.',
'content-length',
'195',
'access-control-allow-credentials',
'true',
'vary',
'origin',
'vary',
'access-control-request-method',
'vary',
'access-control-request-headers',
'access-control-expose-headers',
'dg-model-name,dg-model-uuid,dg-char-count,dg-request-id,dg-error',
'dg-request-id',
'26bb91ce-3daf-4cfc-889e-af8ac98265c5',
'date',
'Tue, 07 Jan 2025 11:19:29 GMT'
],
rawTrailers: [],
joinDuplicateHeaders: undefined,
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 402,
statusMessage: 'Payment Required',
client: <ref *2> TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'api.deepgram.com',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 6,
connecting: false,
_hadError: false,
_parent: null,
_host: 'api.deepgram.com',
_closeAfterHandlingError: false,
_readableState: [ReadableState],
_writableState: [WritableState],
allowHalfOpen: false,
_maxListeners: undefined,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular *1],
[Symbol(alpncallback)]: null,
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 1568,
[Symbol(kHandle)]: null,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(shapeMode)]: true,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: false,
[Symbol(kSetKeepAliveInitialDelay)]: 0,
[Symbol(kBytesRead)]: 704,
[Symbol(kBytesWritten)]: 607,
[Symbol(connect-options)]: [Object]
},
_consuming: false,
_dumped: true,
req: [Circular *1],
_eventsCount: 1,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(kHeaders)]: {
'content-type': 'application/json',
'dg-error': 'Project does not have enough credits for an ASR request and does not have an overage agreement.',
'content-length': '195',
'access-control-allow-credentials': 'true',
vary: 'origin, access-control-request-method, access-control-request-headers',
'access-control-expose-headers': 'dg-model-name,dg-model-uuid,dg-char-count,dg-request-id,dg-error',
'dg-request-id': '26bb91ce-3daf-4cfc-889e-af8ac98265c5',
date: 'Tue, 07 Jan 2025 11:19:29 GMT'
},
[Symbol(kHeadersCount)]: 20,
[Symbol(kTrailers)]: null,
[Symbol(kTrailersCount)]: 0
},
aborted: true,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'api.deepgram.com',
protocol: 'https:',
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
'content-type': [ 'Content-Type', 'application/json' ],
'x-client-info': [ 'X-Client-Info', '@deepgram/sdk; server; v3.9.0' ],
'user-agent': [ 'User-Agent', '@deepgram/sdk/3.9.0 node/20.11.1' ],
authorization: [
'Authorization',
'Token b30a80f8b77d4d7b1f7901e77a35227a09b49980'
],
'sec-websocket-version': [ 'Sec-WebSocket-Version', 13 ],
'sec-websocket-key': [ 'Sec-WebSocket-Key', 'Tua0z+aRzLzo2nVegBuXIg==' ],
connection: [ 'Connection', 'Upgrade' ],
upgrade: [ 'Upgrade', 'websocket' ],
'sec-websocket-extensions': [
'Sec-WebSocket-Extensions',
'permessage-deflate; client_max_window_bits'
],
host: [ 'Host', 'api.deepgram.com' ]
},
[Symbol(errored)]: null,
[Symbol(kHighWaterMark)]: 16384,
[Symbol(kRejectNonStandardBodyWrites)]: false,
[Symbol(kUniqueHeaders)]: null,
[Symbol(kAborted)]: true,
[Symbol(kError)]: undefined
},
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
[Symbol(kType)]: 'error',
[Symbol(kError)]: Error: Unexpected server response: 402
at ClientRequest. (/Users/piyush/Documents/Code/Node/voice-socket/node_modules/ws/lib/websocket.js:913:7)
at ClientRequest.emit (node:events:518:28)
at HTTPParser.parserOnIncomingClient (node:_http_client:693:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:535:22)
at TLSSocket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23),
[Symbol(kMessage)]: 'Unexpected server response: 402'
}
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant