Overview
SdkError is the abstract base class for all errors thrown by the Auth0 Next.js SDK. All SDK error classes extend from this base class and include a code property that identifies the specific error type.
Class Definition
Properties
A unique string identifier for the error type. Use this property to programmatically handle different error scenarios instead of using
instanceof checks.A human-readable error message inherited from the JavaScript
Error class.The name of the error class (e.g.,
"AccessTokenError", "AuthorizationError"). Inherited from the JavaScript Error class.Error Hierarchy
All SDK errors extend fromSdkError:
Error Handling Pattern
The recommended approach for handling SDK errors is to check thecode property rather than using instanceof checks:
Importing Errors
All error classes are exported from the@auth0/nextjs-auth0/errors package:
Type Safety
For TypeScript users, you can use type guards to narrow error types:Best Practices
✓ Use error codes
Always check the
code property to identify specific error types. This is more reliable than instanceof checks.✓ Handle specific errors
Handle specific error codes that are relevant to your application flow rather than catching all errors generically.
✗ Avoid instanceof
Don’t rely on
instanceof checks for error handling. Use the code property instead.✗ Don't expose sensitive data
Some error messages (like
OAuth2Error) may contain reflected user input. Never render error messages directly without proper escaping.Related
- OAuth Errors - OAuth 2.0 and OIDC related errors
- DPoP Errors - DPoP-specific errors
- MFA Errors - Multi-factor authentication errors