import axios from "axios"; import { isArray } from "lodash"; import { InvalidResponse } from '@/defs'; export type ValidResponse = { result: true } export async function callSammoAPI(path: string | string[], args?: Record): Promise; export async function callSammoAPI(path: string | string[], args: Record | undefined, returnError: false): Promise; export async function callSammoAPI(path: string | string[], args: Record | undefined, returnError: true): Promise; export async function callSammoAPI(path: string | string[], args?: Record, returnError = false): Promise { if (isArray(path)) { path = path.join('/'); } const response = await axios({ url: "api.php", method: "post", responseType: "json", data: { path, args, }, }); const result: ErrorType | ResultType = response.data; if (!result.result) { if (returnError) { return result; } throw result.reason; } return result; }