Skip to main content

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

string
required
A unique string identifier for the error type. Use this property to programmatically handle different error scenarios instead of using instanceof checks.
string
required
A human-readable error message inherited from the JavaScript Error class.
string
required
The name of the error class (e.g., "AccessTokenError", "AuthorizationError"). Inherited from the JavaScript Error class.

Error Hierarchy

All SDK errors extend from SdkError:

Error Handling Pattern

The recommended approach for handling SDK errors is to check the code 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.