Class: AuthenticationError
Error thrown when authentication fails. Use for missing tokens, invalid credentials, or authorization failures.
Example
throw new AuthenticationError("User token is required");
throw new AuthenticationError("Failed to generate credentials", { cause: originalError });
Extends
Constructors
Constructor
new AuthenticationError(message: string, options?: {
cause?: Error;
context?: Record<string, unknown>;
}): AuthenticationError;
Parameters
| Parameter | Type |
|---|---|
message | string |
options? | { cause?: Error; context?: Record<string, unknown>; } |
options.cause? | Error |
options.context? | Record<string, unknown> |
Returns
AuthenticationError
Inherited from
Properties
cause?
readonly optional cause: Error;
Optional cause of the error
Inherited from
code
readonly code: "AUTHENTICATION_ERROR" = "AUTHENTICATION_ERROR";
Error code for programmatic error handling
Overrides
context?
readonly optional context: Record<string, unknown>;
Additional context for the error
Inherited from
isRetryable
readonly isRetryable: false = false;
Whether this error type is generally safe to retry
Overrides
statusCode
readonly statusCode: 401 = 401;
HTTP status code suggestion (can be overridden)
Overrides
Methods
toJSON()
toJSON(): Record<string, unknown>;
Convert error to JSON for logging/serialization. Sensitive values in context are automatically redacted.
Returns
Record<string, unknown>
Inherited from
toString()
toString(): string;
Create a human-readable string representation
Returns
string
Inherited from
credentialsFailed()
static credentialsFailed(instance: string, cause?: Error): AuthenticationError;
Create an authentication error for credential generation failure
Parameters
| Parameter | Type |
|---|---|
instance | string |
cause? | Error |
Returns
AuthenticationError
missingToken()
static missingToken(tokenType: string): AuthenticationError;
Create an authentication error for missing token
Parameters
| Parameter | Type | Default value |
|---|---|---|
tokenType | string | "access token" |
Returns
AuthenticationError
missingUserId()
static missingUserId(): AuthenticationError;
Create an authentication error for missing user identity
Returns
AuthenticationError
userLookupFailed()
static userLookupFailed(cause?: Error): AuthenticationError;
Create an authentication error for failed user lookup
Parameters
| Parameter | Type |
|---|---|
cause? | Error |
Returns
AuthenticationError