({ method = "GET", path: apiPath, data, params, auth = true })
| 166 | } |
| 167 | |
| 168 | async request({ method = "GET", path: apiPath, data, params, auth = true }) { |
| 169 | const options = { |
| 170 | method, |
| 171 | url: `${API_BASE}${apiPath.startsWith("/") ? apiPath : `/${apiPath}`}`, |
| 172 | headers: this.getHeaders({}, auth), |
| 173 | timeout: 15000, |
| 174 | validateStatus: () => true, |
| 175 | }; |
| 176 | if (params) options.params = params; |
| 177 | if (data !== undefined) options.data = data; |
| 178 | |
| 179 | const { data: result, status } = await axios.request(options); |
| 180 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 181 | if (!isSuccess(result)) throw new Error(result?.msg || JSON.stringify(result)); |
| 182 | return result.data; |
| 183 | } |
| 184 | |
| 185 | async getLoginCode() { |
| 186 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected