{"version":3,"file":"D6NCsGrY.js","sources":["../../../../composables/useErrors.ts","../../../../composables/useApi.ts"],"sourcesContent":["import { COMMON_CONSTANTS } from \"~/constants/common-constants\";\n\nexport interface ErrorInfo {\n errorCode: number;\n error: string;\n type: string;\n}\n\nexport interface DialogInfo {\n statusCode: number;\n dialogText: string;\n}\n\nexport interface ErrorsComposition {\n handleErrorResponse(response: any): ErrorInfo;\n}\n\nexport const useErrors = (): ErrorsComposition => {\n const handleErrorResponse = (response: any): ErrorInfo => {\n let errorMsg = COMMON_CONSTANTS.DEFAULT_ERROR_MESSAGE;\n if (!response) {\n return {\n errorCode: 0,\n error: errorMsg,\n type: \"\",\n };\n }\n switch (response.status) {\n case 404:\n errorMsg = COMMON_CONSTANTS.DEFAULT_ERROR_MESSAGE_404;\n break;\n case 401:\n case 403:\n case 422:\n case 427:\n case 429:\n errorMsg = response.data.message || errorMsg;\n break;\n default:\n break;\n }\n\n return {\n errorCode: response.status,\n error: errorMsg,\n type: response.type || \"\",\n };\n };\n\n return {\n handleErrorResponse,\n };\n};\n","import type { IApi } from \"~/types/common\";\n\nexport function useApi(): IApi {\n const { $api: api }: any = useNuxtApp();\n\n const toQueryString = (params: any) => {\n if (!params) return \"\";\n return new URLSearchParams(params).toString();\n };\n\n const apiCall = async (\n url: string,\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n body?: any,\n options?: any\n ): Promise => {\n const config = {\n method,\n url,\n data: body,\n ...options,\n };\n const response = await api(config);\n return response;\n };\n\n const get = async (url: string, options?: any): Promise => {\n const queryString = options?.params\n ? `?${toQueryString(options.params)}`\n : \"\";\n return await apiCall(`${url}${queryString}`, \"GET\");\n };\n\n const post = async (url: string, body: any, options?: any): Promise => {\n return await apiCall(url, \"POST\", body, options);\n };\n\n const put = async (url: string, body: any, options?: any): Promise => {\n return await apiCall(url, \"PUT\", body, options);\n };\n\n const del = async (url: string, options?: any): Promise => {\n return await apiCall(url, \"DELETE\", undefined, options);\n };\n\n return { get, post, put, del };\n}\n"],"names":["useErrors","response","errorMsg","COMMON_CONSTANTS","useApi","api","useNuxtApp","toQueryString","params","apiCall","url","method","body","options","config","queryString"],"mappings":"0CAiBO,MAAMA,EAAY,KAgChB,CACL,oBAhC2BC,GAA6B,CACxD,IAAIC,EAAWC,EAAiB,sBAChC,GAAI,CAACF,EACI,MAAA,CACL,UAAW,EACX,MAAOC,EACP,KAAM,EACR,EAEF,OAAQD,EAAS,OAAQ,CACvB,IAAK,KACHC,EAAWC,EAAiB,0BAC5B,MACF,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACL,IAAK,KACQD,EAAAD,EAAS,KAAK,SAAWC,EACpC,KAEA,CAGG,MAAA,CACL,UAAWD,EAAS,OACpB,MAAOC,EACP,KAAMD,EAAS,MAAQ,EACzB,CACF,CAIA,GCjDK,SAASG,GAAe,CAC7B,KAAM,CAAE,KAAMC,CAAI,EAASC,EAAW,EAEhCC,EAAiBC,GAChBA,EACE,IAAI,gBAAgBA,CAAM,EAAE,SAAS,EADxB,GAIhBC,EAAU,MACdC,EACAC,EACAC,EACAC,IACe,CACf,MAAMC,EAAS,CACb,OAAAH,EACA,IAAAD,EACA,KAAME,EACN,GAAGC,CACL,EAEO,OADU,MAAMR,EAAIS,CAAM,CAEnC,EAqBA,MAAO,CAAE,IAnBG,MAAUJ,EAAaG,IAA8B,CACzD,MAAAE,EAAcF,GAAA,MAAAA,EAAS,OACzB,IAAIN,EAAcM,EAAQ,MAAM,CAAC,GACjC,GACJ,OAAO,MAAMJ,EAAW,GAAGC,CAAG,GAAGK,CAAW,GAAI,KAAK,CACvD,EAcc,KAZD,MAAUL,EAAaE,EAAWC,IACtC,MAAMJ,EAAWC,EAAK,OAAQE,EAAMC,CAAO,EAWhC,IARR,MAAUH,EAAaE,EAAWC,IACrC,MAAMJ,EAAWC,EAAK,MAAOE,EAAMC,CAAO,EAO1B,IAJb,MAAUH,EAAaG,IAC1B,MAAMJ,EAAWC,EAAK,SAAU,OAAWG,CAAO,CAG9B,CAC/B"}