You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No way to detect a new Twilio.Device is created with an expired token. Promise returned when device.connect() never settles, keeps on pending state.
#85
Closed
4 of 8 tasks
nnombela opened this issue
Mar 30, 2022
· 4 comments
It will raise a TwilioError having the original error '31202, Access Token expired or expiration date invalid' set in field originalError
The returned promise when device.connect() should be settled as rejected when an expired token is used.
Actual behavior:
twilio-2.1.1.js:4453 WebSocket opened successfully.
twilio-2.1.1.js:4453 Setting token and publishing listen
twilio-2.1.1.js:4453 Received error: ConnectionError: ConnectionError (53000): Raised whenever a signaling connection error occurs that is not covered by a more specific error code.
at ConnectionError.TwilioError [as constructor] (twilio-2.1.1.js:4041:28)
at new ConnectionError (twilio-2.1.1.js:3774:32)
at PStream._handleTransportMessage (twilio-2.1.1.js:5361:33)
at emitOne (twilio-2.1.1.js:10984:13)
at WSTransport.emit (twilio-2.1.1.js:11062:7)
at WebSocket.WSTransport._this._onSocketMessage (twilio-2.1.1.js:9532:19)
Also the returned promise from device.connect() never settles, keeps on pending state.
The problem about the error not having tje orignal error can be solved by incluiding it when creating the TwilioError as shown below, this is an easy fix, no need to create a pull request
I just ran into this bug via a different route.
My app creates a Device early in its lifecycle and then sometime later make the connect call when the user has decided who to call.
The behavior I expected was that the Device would start the timer to request a new token as soon as it was created (which is implied by the docs) and not after connect is called.
Is the best practice to create a Device and connect almost immediately?
@jbgh2 you don't need to connect immediately after creating a Device. However, you need to make sure the Device contains a valid token. To detect if the token is expired:
When you create a new device, you need to listen to device.on('error') events. The device will emit an AccessTokenExpired error if you initialized it with an expired token
@nnombela thank you for reporting. As mentioned above, you can listen to device.on('error') event after you created the device object. An AccessTokenExpired error will be emitted if you provided an expired token.
or sensitive account information (API keys, credentials, etc.) when reporting this issue.
Code to reproduce the issue:
Expected behavior:
It will raise a TwilioError having the original error '31202, Access Token expired or expiration date invalid' set in field originalError
The returned promise when device.connect() should be settled as rejected when an expired token is used.
Actual behavior:
Also the returned promise from device.connect() never settles, keeps on pending state.
The problem about the error not having tje orignal error can be solved by incluiding it when creating the TwilioError as shown below, this is an easy fix, no need to create a pull request
Software versions:
The text was updated successfully, but these errors were encountered: