({ method = "GET", apiPath, query = {}, data = null, token = this.token, allowFail = false })
| 154 | } |
| 155 | |
| 156 | async request({ method = "GET", apiPath, query = {}, data = null, token = this.token, allowFail = false }) { |
| 157 | const options = { |
| 158 | method, |
| 159 | url: buildUrl(apiPath, query), |
| 160 | headers: buildSignedHeaders({ data: method === "GET" ? null : data, token }), |
| 161 | timeout: 15000, |
| 162 | validateStatus: () => true, |
| 163 | }; |
| 164 | if (method !== "GET") options.data = data || {}; |
| 165 | |
| 166 | const { status, data: result } = await axios.request(options); |
| 167 | const ok = status === 200 && String(result?.code) === "200"; |
| 168 | if (!ok && !allowFail) { |
| 169 | throw new Error(`HTTP ${status} ${JSON.stringify(result)}`); |
| 170 | } |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | async getWxCode() { |
| 175 | const wxServerUrl = process.env.wx_server_url; |
no test coverage detected