UNPKG

@ledgerhq/live-common

Version:
45 lines 1.27 kB
/** * Type guard to check if error is a FetchBaseQueryError */ export function isFetchBaseQueryError(error) { return typeof error === "object" && error !== null && "status" in error; } /** * Check if the error is a network connectivity error (no internet, timeout, etc.) */ export function isNetworkError(error) { if (!isFetchBaseQueryError(error)) { return false; } return error.status === "FETCH_ERROR" || error.status === "TIMEOUT_ERROR"; } /** * Check if the error is an API error with HTTP status code (4xx, 5xx) */ export function isApiError(error) { if (!isFetchBaseQueryError(error)) { return false; } return typeof error.status === "number"; } /** * Get HTTP status code from API error, or undefined if not an API error */ export function getApiErrorStatus(error) { if (!isFetchBaseQueryError(error) || typeof error.status !== "number") { return undefined; } return error.status; } /** * Parse error into a structured ErrorInfo object */ export function parseError(error) { return { hasError: !!error, isNetworkError: isNetworkError(error), isApiError: isApiError(error), apiStatus: getApiErrorStatus(error), }; } //# sourceMappingURL=errorUtils.js.map