okta-sdk-nodejs icon indicating copy to clipboard operation
okta-sdk-nodejs copied to clipboard

DRAFT: Proposed error improvements

Open robertjd opened this issue 5 years ago • 2 comments

There are two common configuration errors that developers run into:

  • Invalid API token
  • Invalid Org URL (DNS name not found)

In either situation, the underlying HTTP error bubbles up the promise chain.

If the developer has not implemented a catch, they get a generic error about an uncaught promise exception

This improves on that by printing the exceptions for the common cases above, then exiting the process with a non-zero code

You can reproduce the problematic case by running this:

const okta = require('@okta/okta-sdk-nodejs');

const client = new okta.Client({
  orgUrl: 'https://fooasdoasdfj.okta-asdofij.com',
  token: 'foo',
  requestExecutor: new okta.DefaultRequestExecutor()
});


client.listUsers().each(user => {
  console.log(user)
}).then(() => {
  console.log("Listed users.");
  process.exit();
})

robertjd avatar Apr 02 '19 23:04 robertjd

I definitely support logging the error. Killing the process may be a bit severe. The Okta integration could be a small part of a much larger application.

aarongranick-okta avatar Apr 02 '19 23:04 aarongranick-okta

I definitely support logging the error. Killing the process may be a bit severe. The Okta integration could be a small part of a much larger application.

That's a good point, we shouldn't exit. I was doing the exit to try to avoid the "UnhandledPromiseRejectionWarning" also being printed, but maybe there's not a good way to do that?

robertjd avatar Apr 02 '19 23:04 robertjd