(method, urlPath, { token = "", data = null, params = null, headers = {} } = {})
| 106 | } |
| 107 | |
| 108 | async function request(method, urlPath, { token = "", data = null, params = null, headers = {} } = {}) { |
| 109 | const res = await axios({ |
| 110 | method, |
| 111 | url: `${API_BASE}${urlPath}`, |
| 112 | data, |
| 113 | params, |
| 114 | timeout: 15000, |
| 115 | validateStatus: () => true, |
| 116 | headers: { |
| 117 | version: "1.0", |
| 118 | "User-Agent": "Mozilla/5.0 MicroMessenger MiniProgramEnv/Windows", |
| 119 | Referer: `https://servicewechat.com/${MINI_APP_ID}/250/page-frame.html`, |
| 120 | "X-Call-Client-Info": clientInfo(), |
| 121 | ...(token ? { Authorization: `Bearer ${token}` } : {}), |
| 122 | ...headers, |
| 123 | }, |
| 124 | }); |
| 125 | return res.data; |
| 126 | } |
| 127 | |
| 128 | function assertOk(res, action) { |
| 129 | if (!res || res.hasError || String(res.responseCode) !== "0") { |
no test coverage detected