UNPKG

@zendesk/zcli-themes

Version:

zcli theme commands live here

37 lines (36 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Parses an AxiosError to extract message and response, handling quirks with the fetch adapter. * * When axios uses adapter: 'fetch', it creates nested errors where: * - The actual response is in error.cause.response instead of error.response * - The response.data is an unparsed JSON string instead of a parsed object * * This function normalizes the error structure across different axios configurations. * * @param error - The AxiosError to parse * @returns An object containing the error message and normalized response (if any) */ function parseAxiosError(error) { var _a; let response = error.response; const errorWithCause = error; if (!response && ((_a = errorWithCause.cause) === null || _a === void 0 ? void 0 : _a.response)) { response = errorWithCause.cause.response; } // Handle axios fetch adapter quirk: data might be unparsed JSON string if (response && typeof response.data === 'string') { try { response.data = JSON.parse(response.data); } catch (_b) { // Keep as string if not valid JSON } } return { message: error.message, response }; } exports.default = parseAxiosError;