node-auth0 icon indicating copy to clipboard operation
node-auth0 copied to clipboard

Export an Error type that can be caught and handled

Open Pipeliner opened this issue 3 years ago • 2 comments

Describe the problem you'd like to have solved

On errors, Auth0 throws Error objects that can't be easily differentiated from other kind of errors. e.g. PasswordlessAuthenticator.signIn() can throw a lot of different errors depending on problems with the token / user being blocked / etc.

I can't easily differentiate these errors from other errors that might happen in my code or other libraries.

Describe the ideal solution

There is a base class for Auth0 errors (and maybe subclasses for specific errors)

Alternatives and current work-arounds

I can try to catch SanitizedErrors which happen to be the errors which Auth0 usually throw. However, this is not documented anywhere and is there not guaranteed to be the case.

Additional information, if any

--

Pipeliner avatar May 10 '22 17:05 Pipeliner

Yes, +1 to this. I am also noticing that the error description is not simple to derive either. I am looking to extract the following to return in the response to several requests (password grant, database signup, request change password email, and update auth0 user):

  1. The status code
  2. A human-readable message

I have looked through the code of both this library and rest-facade in these locations:

  • https://github.com/ngonzalvez/rest-facade/blob/master/src/exceptions/APIError.js
  • https://github.com/auth0/node-auth0/blob/master/src/errors.js

Status Code ✅

The error.statusCode is consistently available for this value.

Message ❓

I am currently using the error.message field, a stringified json object. I am noticing the object has an inconsistent shape, depending on the error/action. Based on the examples I've seen, I am using the parsed error.message description or error_description as of right now. It would be great, if this were derived for clients in a more consistent, clear way.

What is the best way to extract a human-readable error message?

A few examples with inconsistencies:

Password grant with wrong password

I am seeing the following:

{
  error: 'invalid_grant',
  error_description: 'Wrong email or password.'
}

Database signup user exists

I am seeing the following:

{
  name: 'BadRequestError',
  code: 'user_exists',
  description: 'The user already exists.',
  statusCode: 400
}

nicholeuf avatar May 16 '22 12:05 nicholeuf

Thanks for raising this @Pipeliner

I don't see a short term solution to this, but I'll leave this open as an enhancement for when we consider the next iteration of this SDK

adamjmcgrath avatar May 19 '22 07:05 adamjmcgrath

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

stale[bot] avatar Oct 30 '22 12:10 stale[bot]