Code Monkey home page Code Monkey logo

Comments (3)

sjwalter avatar sjwalter commented on June 8, 2024

Ah, yes. This is because the error is happening asynchronously. That is,
setup() goes and makes an asynchronous request to Twilio, having stored a
reference to your callback. When the error is thrown, your call to setup()
has already returned, and hence falls outside of the scope of your
try-catch block.

The right thing to do here would be to clean up the interface such that
instead of throw'ing the error, the error is passed into the callback for
setup. This would make the call work like...

phone.setup(function(err) {
if (err) {
// Here, error would be the error that's being thrown.
}
});

Unfortunately, I didn't write the library that way. Also, I have so little
spare time right now that finishing the refactor job I've started is going
to take a while. I do accept pull requests though!

Happy hacking,
Stephen

On Mon, Jan 30, 2012 at 1:58 PM, robertjd <
[email protected]

wrote:

With the following code:

var phone_number = "12345";
var phone = client.getPhoneNumber(phone_number);
phone.setup(function() { })

If phone_number does not exist in your account, the following is thrown:


                   throw new Error('Could not get number ' +

^

Error: Could not get number 1234
   at
/Users/robert/colingo/Express/node_modules/twilio/lib/twilio.js:142:27
   at IncomingMessage.<anonymous>
(/Users/robert/colingo/Express/node_modules/twilio/lib/rest-client.js:86:41)
   at IncomingMessage.emit (events.js:81:20)
   at HTTPParser.onMessageComplete (http.js:133:23)
   at CleartextStream.ondata (http.js:1231:22)
   at CleartextStream._push (tls.js:303:27)
   at SecurePair.cycle (tls.js:577:20)
   at EncryptedStream.write (tls.js:96:13)
   at Socket.ondata (stream.js:36:26)
   at Socket.emit (events.js:64:17)

I have found that putting try/catch around the call to phone.setup() does
not actually catch the error.

Two questions:

1.) Why does my try/catch not work?

2.) Is there a better way to check that a number exists in an account?


Reply to this email directly or view it on GitHub:
https://github.com/sjwalter/node-twilio/issues/22

from node-twilio.

robertjd avatar robertjd commented on June 8, 2024

Hey Stephen, thanks for the info on the try/catch issue! I has a suspicion it was such.

I will need to do the modifications you mention (passing back an error parameter) to make this robust for our app. I'll definitely submit a pull when I've got that done.

Cheers

from node-twilio.

ukd1 avatar ukd1 commented on June 8, 2024

This library is deprecated in favor of the official library - https://github.com/twilio/twilio-node

from node-twilio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.