@zendesk/zcli-themes
Version:
zcli theme commands live here
18 lines (17 loc) • 734 B
TypeScript
import type { AxiosError, AxiosResponse } from 'axios';
/**
* 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)
*/
export default function parseAxiosError(error: AxiosError): {
message: string;
response: AxiosResponse | undefined;
};