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

Improve errors [SDK-3552] #782

Merged
merged 10 commits into from
Aug 17, 2022
Merged

Improve errors [SDK-3552] #782

merged 10 commits into from
Aug 17, 2022

Conversation

Widcket
Copy link
Contributor

@Widcket Widcket commented Aug 17, 2022

⚠️ This PR contains breaking changes

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

This PR reworks the SDK errors to:

  1. Improve error handling.
  2. Set up a base that better accommodates typed errors. Individual error classes for specific common errors are not included in this PR, but are very simple to add.

Underlying errors

Now, SDK errors can inherit from the base AuthError, which contains a cause? property for an underlying error. This way, errors can wrap another error simply by populating this property. The message of the 'wrapped' error will be automatically appended to the message of the 'wrapper' error (and labeled accordingly), which makes it easily discoverable and actionable by the developer.

Error codes

SDK errors that inherit from AuthError will need to specify a machine-readable code. Developers can rely on error codes to identify specific errors. Unlike error messages, codes are part of the SDK API and will remain stable within a major version of the SDK. The error codes follow the ERR_SOMETHING Node.js convention.

Error names

SDK errors that inherit from AuthError will need to specify a value for the name property (typically the error class name). This value will show up when printing an error with console.log(error), making it easier for the developer to identify the error.

API handler-specific errors

Before, HandlerError was the single catch-all error for all errors produced by an API handler. Now every handler has its own error:

  • CallbackHandlerError for the errors of the callback handler
  • LoginHandlerError for the errors of the login handler
  • LogoutHandlerError for the errors of the logout handler
  • ProfileHandlerError for the errors of the profile handler

This makes it possible for handler-specific errors to feature handler-specific codes. The end result is that every handler will only throw errors of a single type, with a machine-readable code, and a single wrapped error. Which greatly simplifies error handling.

@Widcket Widcket added the CH: Breaking Change PR contains breaking changes without a major version bump label Aug 17, 2022
@vercel
Copy link

vercel bot commented Aug 17, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nextjs-auth0 ⬜️ Ignored (Inspect) Aug 17, 2022 at 4:16AM (UTC)

@Widcket Widcket marked this pull request as ready for review August 17, 2022 03:47
@Widcket Widcket requested a review from a team as a code owner August 17, 2022 03:47
@Widcket Widcket changed the base branch from main to vNext August 17, 2022 04:06
@Widcket Widcket force-pushed the feature/improved-errors branch 3 times, most recently from bf29ee4 to 96adbc9 Compare August 17, 2022 04:15
@Widcket Widcket merged commit 46b1803 into vNext Aug 17, 2022
@Widcket Widcket deleted the feature/improved-errors branch August 17, 2022 12:00
@adamjmcgrath adamjmcgrath mentioned this pull request Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Breaking Change PR contains breaking changes without a major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants