sjwalter/node-twilio — Issue #22: Error 'Could not get number '
Author: robertjd
Created: 2012-01-30 21:58:33+00:00
State: open

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:

```../node_modules/twilio/lib/twilio.js:142

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. (/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?