(apiPath, data = {}, method = "GET", options = {})
| 184 | } |
| 185 | |
| 186 | async request(apiPath, data = {}, method = "GET", options = {}) { |
| 187 | const payload = options.enterpriseNo ? { ...data } : { enterpriseNo: ENTERPRISE_NO, ...data }; |
| 188 | const requestOptions = { |
| 189 | method, |
| 190 | url: `${API_BASE}/${apiPath}`, |
| 191 | headers: this.getHeaders(method, apiPath, payload), |
| 192 | timeout: 20000, |
| 193 | validateStatus: () => true, |
| 194 | }; |
| 195 | if (method.toUpperCase() === "GET") requestOptions.params = payload; |
| 196 | else requestOptions.data = payload; |
| 197 | |
| 198 | const { status, data: result } = await axios.request(requestOptions); |
| 199 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 200 | if (!options.allowAnyCode && result?.code !== 200) { |
| 201 | const err = new Error(result?.message || JSON.stringify(result)); |
| 202 | err.code = result?.code; |
| 203 | throw err; |
| 204 | } |
| 205 | return result; |
| 206 | } |
| 207 | |
| 208 | async getLoginCode() { |
| 209 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected