Comments (3)
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.
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.
This library is deprecated in favor of the official library - https://github.com/twilio/twilio-node
from node-twilio.
Related Issues (20)
- Example SMS Send Erroring - Could Not Get Number HOT 4
- Is there any way to have one service listen for multiple numbers? HOT 3
- Twilio hangs up immediately , events not firing HOT 1
- Is there mandatory events with incomingCall? HOT 1
- Modules object is deprecated HOT 2
- Use on dev machines. HOT 3
- undefined request params HOT 2
- Timeouts on heroku HOT 4
- Dial Syntax? HOT 2
- Changing "hostname" to "base_url" HOT 1
- broken again latest express HOT 1
- Setting the URI for a call/text doesn't change the request type HOT 1
- Need more documentation of Twiml.Gather(); HOT 2
- Facilitate Paging? HOT 1
- autoUri is global, and is reported as problem for unit tests like mocha HOT 1
- Is this package still supported? HOT 2
- Documentation link is outdated
- express dependency missing from package.json HOT 2
- Library incompatible with Heroku, etc HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-twilio.