UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

53 lines • 1.91 kB
import type { ApiError } from '../models/interfaces'; /** * Error handling utilities for consistent error processing */ /** * Common error codes */ export declare const ErrorCodes: { readonly UNAUTHORIZED: "UNAUTHORIZED"; readonly FORBIDDEN: "FORBIDDEN"; readonly INVALID_TOKEN: "INVALID_TOKEN"; readonly MISSING_TOKEN: "MISSING_TOKEN"; readonly VALIDATION_ERROR: "VALIDATION_ERROR"; readonly BAD_REQUEST: "BAD_REQUEST"; readonly MISSING_PARAMETER: "MISSING_PARAMETER"; readonly INVALID_FORMAT: "INVALID_FORMAT"; readonly NOT_FOUND: "NOT_FOUND"; readonly ALREADY_EXISTS: "ALREADY_EXISTS"; readonly CONFLICT: "CONFLICT"; readonly INTERNAL_ERROR: "INTERNAL_ERROR"; readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE"; readonly TIMEOUT: "TIMEOUT"; readonly NETWORK_ERROR: "NETWORK_ERROR"; readonly CONNECTION_FAILED: "CONNECTION_FAILED"; }; /** * Create a standardized API error */ export declare function createApiError(message: string, code?: string, status?: number, details?: Record<string, unknown>): ApiError; /** * Handle common HTTP errors and convert to ApiError */ export declare function handleHttpError(error: unknown): ApiError; /** * Get error code from HTTP status * Exported for use in other modules */ export declare function getErrorCodeFromStatus(status: number): string; /** * Validate required fields and throw error if missing */ export declare function validateRequiredFields(data: Record<string, unknown>, fields: string[]): void; /** * Safe error logging with context */ export declare function logError(error: unknown, context?: string): void; /** * Retry function with exponential backoff * Re-exports retryAsync for backward compatibility * @deprecated Use retryAsync from asyncUtils instead */ export { retryAsync as retryWithBackoff } from './asyncUtils'; //# sourceMappingURL=errorUtils.d.ts.map