(method, apiPath, data = {}, options = {})
| 151 | } |
| 152 | |
| 153 | async request(method, apiPath, data = {}, options = {}) { |
| 154 | const requestOptions = { |
| 155 | method, |
| 156 | url: `${API_BASE}/${apiPath}`, |
| 157 | headers: this.getHeaders(options.auth), |
| 158 | timeout: 20000, |
| 159 | validateStatus: () => true, |
| 160 | }; |
| 161 | if (method === "GET") requestOptions.params = data; |
| 162 | else requestOptions.data = data; |
| 163 | |
| 164 | const { status, data: result } = await axios.request(requestOptions); |
| 165 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 166 | if (!options.allowAnyCode && result?.resultCode !== "1") { |
| 167 | const err = new Error(result?.msg || JSON.stringify(result)); |
| 168 | err.resultCode = result?.resultCode; |
| 169 | throw err; |
| 170 | } |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | async getLoginCode() { |
| 175 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected