@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
52 lines • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isFetchBaseQueryError = isFetchBaseQueryError;
exports.isNetworkError = isNetworkError;
exports.isApiError = isApiError;
exports.getApiErrorStatus = getApiErrorStatus;
exports.parseError = parseError;
/**
* Type guard to check if error is a FetchBaseQueryError
*/
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.)
*/
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)
*/
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
*/
function getApiErrorStatus(error) {
if (!isFetchBaseQueryError(error) || typeof error.status !== "number") {
return undefined;
}
return error.status;
}
/**
* Parse error into a structured ErrorInfo object
*/
function parseError(error) {
return {
hasError: !!error,
isNetworkError: isNetworkError(error),
isApiError: isApiError(error),
apiStatus: getApiErrorStatus(error),
};
}
//# sourceMappingURL=errorUtils.js.map