node-apis
Version:
🚀 Advanced TypeScript API generator with clean architecture, comprehensive testing, and automatic formatting. Generate production-ready Node.js APIs with complete integration test suites.
65 lines • 2.41 kB
JavaScript
;
/**
* Centralized error constants for consistent error handling
*
* @see https://trpc.io/docs/server/error-handling
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERROR_NAMES = exports.ERROR_MESSAGES = exports.TRPC_ERROR_CODES = void 0;
/**
* tRPC error codes mapped to HTTP status codes
* Use these constants instead of hardcoded strings
*/
exports.TRPC_ERROR_CODES = {
BAD_REQUEST: 'BAD_REQUEST',
UNAUTHORIZED: 'UNAUTHORIZED',
FORBIDDEN: 'FORBIDDEN',
NOT_FOUND: 'NOT_FOUND',
TIMEOUT: 'TIMEOUT',
CONFLICT: 'CONFLICT',
PRECONDITION_FAILED: 'PRECONDITION_FAILED',
PAYLOAD_TOO_LARGE: 'PAYLOAD_TOO_LARGE',
TOO_MANY_REQUESTS: 'TOO_MANY_REQUESTS',
CLIENT_CLOSED_REQUEST: 'CLIENT_CLOSED_REQUEST',
INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
};
/**
* Standard error messages for common scenarios
* Update these messages in one place for consistency
*/
exports.ERROR_MESSAGES = {
// Generic errors
INTERNAL_ERROR: 'An unexpected error occurred. Please try again later.',
NOT_IMPLEMENTED: 'This feature is not yet implemented.',
// Authentication & Authorization
UNAUTHORIZED: 'You must be logged in to perform this action.',
FORBIDDEN: 'You do not have permission to perform this action.',
INVALID_CREDENTIALS: 'Invalid email or password.',
SESSION_EXPIRED: 'Your session has expired. Please log in again.',
// Resource errors
NOT_FOUND: 'The requested resource was not found.',
ALREADY_EXISTS: 'This resource already exists.',
// Validation errors
INVALID_INPUT: 'Invalid input provided. Please check your data.',
MISSING_REQUIRED_FIELD: 'Required field is missing.',
// Rate limiting
RATE_LIMIT_EXCEEDED: 'Too many requests. Please try again later.',
// Database errors
DATABASE_ERROR: 'A database error occurred. Please try again.',
TRANSACTION_FAILED: 'Transaction failed. Please try again.',
};
/**
* Error names for catching specific error types
* Use these when checking error.name in handlers
*/
exports.ERROR_NAMES = {
NOT_FOUND: 'NotFoundError',
VALIDATION: 'ValidationError',
DATABASE: 'DatabaseError',
AUTHENTICATION: 'AuthenticationError',
AUTHORIZATION: 'AuthorizationError',
CONFLICT: 'ConflictError',
RATE_LIMIT: 'RateLimitError',
TIMEOUT: 'TimeoutError',
};
//# sourceMappingURL=errors.js.map