Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericError not exported #643

Closed
5 tasks done
elstgav opened this issue Nov 1, 2023 · 1 comment · Fixed by #644
Closed
5 tasks done

GenericError not exported #643

elstgav opened this issue Nov 1, 2023 · 1 comment · Fixed by #644

Comments

@elstgav
Copy link

elstgav commented Nov 1, 2023

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:

@elstgav elstgav mentioned this issue Nov 1, 2023
5 tasks
@frederikprijck
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants