@ingeze/api-error
Version:
A TypeScript library for handling HTTP errors in Express, NestJS, and Fastify APIs.
117 lines • 3.79 kB
TypeScript
/**
* Defines custom error classes for handling various unauthorized scenarios (HTTP 401).
*
* Each class extends `UnauthorizedError`, which itself extends `ErrorHandler`.
* These errors represent specific authentication or authorization failures and provide
* descriptive messages and error types for easier error handling and debugging.
*
* @module errors/unauthorized-error
*/
import type { UnauthorizedErrorType } from '../types/index.js';
import { ErrorHandler } from './error-handler.js';
/**
* Represents a generic unauthorized error (HTTP 401).
*
* This error is thrown when the request requires user authentication
* but the client has failed to provide valid credentials.
*
* Can be instantiated with either a custom message, type, and optional details,
* or directly with a `details` object.
*
* @extends ErrorHandler
*/
export declare class UnauthorizedError extends ErrorHandler {
/**
* Creates a new UnauthorizedError instance with optional details.
*
* @param {Record<string, unknown>=} details - Additional error details related to the authentication failure.
*/
constructor(details?: Record<string, unknown>);
/**
* Creates a new UnauthorizedError instance with a custom message, type, and optional details.
*
* @param {string} message - A custom error message describing the authentication issue.
* @param {UnauthorizedErrorType=} type - A specific unauthorized error type identifier.
* @param {Record<string, unknown>=} details - Additional error details.
*/
constructor(message?: string, type?: UnauthorizedErrorType, details?: Record<string, unknown>);
}
/**
* Error for invalid token.
*
* @extends UnauthorizedError
*/
export declare class InvalidTokenError extends UnauthorizedError {
/**
* Creates a new InvalidTokenError instance.
*
* @param {Record<string, unknown>=} details Optional additional error details.
*/
constructor(details?: Record<string, unknown>);
}
/**
* Error for invalid credentials.
*
* @extends UnauthorizedError
*/
export declare class InvalidCredentialsError extends UnauthorizedError {
/**
* Creates a new InvalidCredentialsError instance.
*
* @param {Record<string, unknown>} details Additional error details.
*/
constructor(details: Record<string, unknown>);
}
/**
* Error for invalid or expired access token.
*
* @extends UnauthorizedError
*/
export declare class AccessTokenError extends UnauthorizedError {
/**
* Creates a new AccessTokenError instance.
*
* @param {Record<string, unknown>} details Additional error details.
*/
constructor(details: Record<string, unknown>);
}
/**
* Error for invalid or expired refresh token.
*
* @extends UnauthorizedError
*/
export declare class RefreshTokenError extends UnauthorizedError {
/**
* Creates a new RefreshTokenError instance.
*
* @param {Record<string, unknown>} details Additional error details.
*/
constructor(details: Record<string, unknown>);
}
/**
* Error for invalid API key.
*
* @extends UnauthorizedError
*/
export declare class APIKeyError extends UnauthorizedError {
/**
* Creates a new APIKeyError instance.
*
* @param {Record<string, unknown>} details Additional error details.
*/
constructor(details: Record<string, unknown>);
}
/**
* Error for unauthorized device.
*
* @extends UnauthorizedError
*/
export declare class UnauthorizedDeviceError extends UnauthorizedError {
/**
* Creates a new UnauthorizedDeviceError instance.
*
* @param {Record<string, unknown>} details Additional error details.
*/
constructor(details: Record<string, unknown>);
}
//# sourceMappingURL=unauthorized-error.d.ts.map