(apiPath, data = {}, options = {})
| 190 | } |
| 191 | |
| 192 | async request(apiPath, data = {}, options = {}) { |
| 193 | const method = (options.method || "POST").toUpperCase(); |
| 194 | const req = { |
| 195 | method, |
| 196 | url: new URL(apiPath, API_BASE).toString(), |
| 197 | headers: this.headers(method, apiPath, data, options.headers || {}), |
| 198 | timeout: 20000, |
| 199 | validateStatus: () => true, |
| 200 | }; |
| 201 | if (method === "GET") req.params = data; |
| 202 | else req.data = data || {}; |
| 203 | |
| 204 | const { data: result, status } = await axios.request(req); |
| 205 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 206 | if (!isSuccess(result)) throw new Error(`${result?.Code ?? ""} ${result?.Message || JSON.stringify(result)}`.trim()); |
| 207 | return result; |
| 208 | } |
| 209 | |
| 210 | async getOperateData() { |
| 211 | if (!process.env.wx_auth) throw new Error("缺少 wx_auth,无法从 wx_server 获取登录数据"); |
no test coverage detected