auth0/auth0-react

GenericError not exported

elstgav opened this issue · 1 comments

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Following up to:

it’s useful to have GenericError exported in addition to the other Error classes. This enables clients to quickly detect if they’re dealing with any kind of Auth0 Error:

import { GenericError, useAuth0 } from '@auth0/auth0-react'

const ErrorComponent = () => {
  const { error } = useAuth0()

  if (error instanceof GenericError) {
    console.log(error.error_description)
  }

  

Describe the ideal solution

In auth0-react/src/index.tsx, export GenericError from auth0-spa-js:

  export {
    …
+   GenericError,
    …
  } from '@auth0/auth0-spa-js';

Alternatives and current workarounds

We can determine the GenericError by grabbing the prototype of any of the child errors:

import { AuthenticationError, useAuth0 } from '@auth0/auth0-react'

const ErrorComponent = () => {
  const { error } = useAuth0()

  const GenericAuth0Error = Object.getPrototypeOf(AuthenticationError)

  if (error instanceof GenericError) {
    console.log(error.error_description)
  }

  

Additional context

All other errors were exported in:

Thanks for reaching out about this, i will make sure to add this, thanks!