{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export function parseErrorMessage( error: any ): string {\n\t// Look for expectable validation errors before moving to generic handling\n\n\t// Are the attributes of a server-rendered block failing the validation\n\t// callback of WP_REST_Block_Renderer_Controller?\n\t//\n\t// @example\n\t// {\n\t//     \"code\": \"rest_invalid_param\",\n\t//     \"message\": \"Invalid parameter(s): attributes\",\n\t//     \"data\": {\n\t//         \"status\": 400,\n\t//         \"params\": {\n\t//             \"attributes\": \"[test][1] is not one of Option1, Option2, and Option3.\"\n\t//         },\n\t//         \"details\": {\n\t//             \"attributes\": {\n\t//                 \"code\": \"rest_not_in_enum\",\n\t//                 \"message\": \"[test][1] is not one of Option1, Option2, and Option3.\",\n\t//                 \"data\": null\n\t//             }\n\t//         }\n\t//     }\n\t// }\n\tif (\n\t\terror?.code === 'rest_invalid_param' &&\n\t\terror.data?.params?.attributes &&\n\t\t1 === Object.values( error.data.params ).length\n\t) {\n\t\treturn `Invalid attribute: ${ error.data.params.attributes }`;\n\t}\n\n\tif ( error instanceof Error ) {\n\t\treturn error.message;\n\t}\n\n\t// Expect certain errors to be plain objects with a `message`\n\t// property, such as those thrown by `apiFetch`. Otherwise, do our\n\t// best to infer a message via duck typing.\n\tif ( ! error ) {\n\t\treturn '';\n\t} else if ( typeof error.message === 'string' ) {\n\t\treturn error.message;\n\t} else if ( typeof error === 'string' ) {\n\t\treturn error;\n\t} else if (\n\t\t// Only consider own method, lest we erroneously end up calling\n\t\t// `Object#toString` at the end of the prototype chain, thereby\n\t\t// returning `\"[object Object]\"`.\n\t\tObject.hasOwn( error, 'toString' ) &&\n\t\ttypeof error.toString === 'function'\n\t) {\n\t\tconst result = error.toString();\n\t\tif ( typeof result === 'string' ) {\n\t\t\treturn result;\n\t\t}\n\t}\n\n\treturn '';\n}\n"],"mappings":";AAAA,SAAgB,kBAAmB,OAAqB;CAwBvD,IACC,OAAO,SAAS,wBAChB,MAAM,MAAM,QAAQ,cACpB,MAAM,OAAO,OAAQ,MAAM,KAAK,MAAO,CAAC,CAAC,QAEzC,OAAO,sBAAuB,MAAM,KAAK,OAAO;CAGjD,IAAK,iBAAiB,OACrB,OAAO,MAAM;CAMd,IAAK,CAAE,OACN,OAAO;MACD,IAAK,OAAO,MAAM,YAAY,UACpC,OAAO,MAAM;MACP,IAAK,OAAO,UAAU,UAC5B,OAAO;MACD,IAIN,OAAO,OAAQ,OAAO,UAAW,KACjC,OAAO,MAAM,aAAa,YACzB;EACD,MAAM,SAAS,MAAM,SAAS;EAC9B,IAAK,OAAO,WAAW,UACtB,OAAO;CAET;CAEA,OAAO;AACR"}