UNPKG

@blue-impact-engine/blue-impact-engine-client

Version:
60 lines 1.94 kB
import { BlueImpactApiError, ApiErrorType } from "../core"; /** * Error handling utilities */ export const errorHandling = { /** * Create a standardized error from various error types * @param error - Error to standardize * @returns BlueImpactApiError - Standardized error */ standardizeError(error) { if (error instanceof BlueImpactApiError) { return error; } if (error instanceof Error) { return new BlueImpactApiError(ApiErrorType.UNKNOWN_ERROR, error.message, undefined, { originalError: error }); } return new BlueImpactApiError(ApiErrorType.UNKNOWN_ERROR, "An unknown error occurred", undefined, { originalError: error }); }, /** * Check if error is retryable * @param error - Error to check * @returns boolean - True if retryable */ isRetryableError(error) { if (error instanceof BlueImpactApiError) { return [ ApiErrorType.RATE_LIMIT_ERROR, ApiErrorType.SERVER_ERROR, ApiErrorType.NETWORK_ERROR, ].includes(error.type); } // Check for network errors if (error.code === "ECONNABORTED" || error.code === "ENOTFOUND") { return true; } return false; }, /** * Extract error message from various error types * @param error - Error to extract message from * @returns string - Error message */ extractErrorMessage(error) { if (error instanceof BlueImpactApiError) { return error.message; } if (error instanceof Error) { return error.message; } if (typeof error === "string") { return error; } if (error?.message) { return error.message; } return "An unknown error occurred"; }, }; //# sourceMappingURL=loggingUtils.js.map