UNPKG

@wandelbots/nova-js

Version:

Official JS client for the Wandelbots API

1 lines 2.58 kB
{"version":3,"file":"index.cjs","names":["AxiosError","tryStringifyJson"],"sources":["../src/lib/errorHandling.ts"],"sourcesContent":["import { AxiosError } from \"axios\"\nimport { tryStringifyJson } from \"./converters\"\n\nexport function delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\n/**\n * @deprecated Use makeErrorMessage instead and truncate the error for display as needed, or make a situation-specific localized error message based on a response code\n */\nexport function makeShortErrorMessage(err: unknown) {\n return makeErrorMessage(err)\n}\n\n/**\n * Attempts to make a helpful error message from an unknown thrown error\n * or promise rejection.\n *\n * This function is mainly to aid debugging and good bug reports. For\n * expected errors encountered by end users, it's more ideal to catch\n * the specific error code and provide a localized app-specific error message.\n */\nexport function makeErrorMessage(err: unknown): string {\n if (err instanceof AxiosError) {\n if (err.response) {\n return `${err.response?.status} ${err.response?.statusText} from ${err.response?.config.method?.toUpperCase() || \"accessing\"} ${err.response?.config.url}: ${JSON.stringify(err.response?.data)}`\n } else if (err.config) {\n if (err.code === \"ERR_NETWORK\") {\n return `${err.message} from ${err.config.method?.toUpperCase() || \"accessing\"} ${err.config.url}. This error can happen because of either connection issues or server CORS policy.`\n } else {\n return `${err.message} from ${err.config.method?.toUpperCase() || \"accessing\"} ${err.config.url}`\n }\n }\n } else if (err instanceof Error) {\n return err.message\n } else if (typeof err === \"string\") {\n return err\n } else if (typeof err === \"object\") {\n return tryStringifyJson(err) || `Unserializable object ${err}`\n }\n\n return `${err}`\n}\n"],"mappings":";;;;;AAGA,SAAgB,MAAM,IAAY;AAChC,QAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;;;;;AAM1D,SAAgB,sBAAsB,KAAc;AAClD,QAAO,iBAAiB,IAAI;;;;;;;;;;AAW9B,SAAgB,iBAAiB,KAAsB;AACrD,KAAI,eAAeA,kBACjB;MAAI,IAAI,SACN,QAAO,GAAG,IAAI,UAAU,OAAO,GAAG,IAAI,UAAU,WAAW,QAAQ,IAAI,UAAU,OAAO,QAAQ,aAAa,IAAI,YAAY,GAAG,IAAI,UAAU,OAAO,IAAI,IAAI,KAAK,UAAU,IAAI,UAAU,KAAK;WACtL,IAAI,OACb,KAAI,IAAI,SAAS,cACf,QAAO,GAAG,IAAI,QAAQ,QAAQ,IAAI,OAAO,QAAQ,aAAa,IAAI,YAAY,GAAG,IAAI,OAAO,IAAI;MAEhG,QAAO,GAAG,IAAI,QAAQ,QAAQ,IAAI,OAAO,QAAQ,aAAa,IAAI,YAAY,GAAG,IAAI,OAAO;YAGvF,eAAe,MACxB,QAAO,IAAI;UACF,OAAO,QAAQ,SACxB,QAAO;UACE,OAAO,QAAQ,SACxB,QAAOC,oCAAiB,IAAI,IAAI,yBAAyB;AAG3D,QAAO,GAAG"}