clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

NameToDomain - Can't catch NameToDomain.NotFoundError #30

Closed BrandonNoad closed 6 years ago

BrandonNoad commented 6 years ago

Hi,

I'm trying to do a filtered catch as show in the documentation. It doesn't seem to work with NameToDomain.NotFoundError.

var NameToDomain = clearbit.NameToDomain;
NameToDomain.find({name: 'UberrebU'})
  .then(function (result) {
    console.log('Domain: ', result.domain);
  })
  .catch(NameToDomain.NotFoundError, function (err) {
    // NEVER GET HERE!
    console.log(err); // Domain could not be found
  })
  .catch(function (err) {
    console.log(err);
    console.log('Bad/invalid request, unauthorized, Clearbit error, or failed request');
  });

When the domain can not be found, it ends up in the last catch block with the following error:

{ ClearbitError: Not Found
    at ClearbitClient.<anonymous> (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/src/client.js:82:22)
    at ClearbitClient.tryCatcher (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/promise.js:508:31)
    at Promise._settlePromiseAt (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/promise.js:584:18)
    at Promise._settlePromises (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/promise.js:700:14)
    at Async._drainQueue (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues (/Users/brandon/code/new-bonfire-organization/node_modules/clearbit/node_modules/bluebird/js/main/async.js:15:14)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)
  message: 'Not Found',
  type: 'unknown',
  body: '{\n  "type": "unknown_record",\n  "message": "Unknown company."\n}',
  statusCode: 404 }
davidlumley commented 6 years ago

Hey @BrandonNoad would you mind including your environment details so I can look into this further? Thanks!

BrandonNoad commented 6 years ago

Using node v6.11.5 (npm v3.10.10) on OS X.

davidlumley commented 6 years ago

Thanks Brandon! Will look into this shortly 👍

davidlumley commented 6 years ago

Hey @BrandonNoad, I traced the issue back to how we were sending through upstream errors. Long story short, they should now be in the correct format. Would you mind being a second set of eyes and checking to see if this has fixed the issue?

BrandonNoad commented 6 years ago

Yes. I can take a look at it. Is there a branch I can checkout?

davidlumley commented 6 years ago

Nope! Because it was to do with how we were rendering error responses there are no changes to the repo, but rather to our upstream APIs.

I've tested, but would be great if you could verify! 👍

BrandonNoad commented 6 years ago

Seems to be working now 😄 Thanks!

davidlumley commented 6 years ago

Thanks for verifying! ❤️