what3words / w3w-node-wrapper

Node wrapper for the What3Words API
https://docs.what3words.com/api/v3/
MIT License
45 stars 10 forks source link

Errors not passed back up #1

Closed bigmonkeyboy closed 9 years ago

bigmonkeyboy commented 9 years ago

Currently any errors in the API cause exceptions - rather than being passed back up to the calling app using callbacks - eg see http://fredkschott.com/post/2014/03/understanding-error-first-callbacks-in-node-js/ Any chance this lib can be changed to do that ?

sabarasaba commented 9 years ago

Hey man,

Thats a good point, I've been thinking for a while about replacing the callbacks with promises and if we ever do that it will be quite easy to return the errors to the user instead of throwing an exception.

You're welcome to send any PR's, if not I will fix this after the holidays :santa:

sabarasaba commented 9 years ago

This got implemented with 1ce84f71063774d772ece7afc4ebbaf66f72c4c0

eg:

var w3w = new What3Words(API_KEY);

w3w.wordsToPosition({ words: 'prom.cape.pump' })
  .then(function(res) {
    console.log(res);
  })
  .catch(function(err) {
    console.log(err);
  });
bigmonkeyboy commented 9 years ago

Excellent, any chance you can bump your version no in package.json and re-publish to npm ? many thanks for the quick fix.

sabarasaba commented 9 years ago

Ahg, I knew I forgot to do something! Just published it, happy new year man :tada:

bigmonkeyboy commented 9 years ago

Perfect - and all the best for a Happy New Year to you also !