({ method = "GET", path: apiPath, params = {}, data = {}, skipToken = false })
| 161 | } |
| 162 | |
| 163 | async request({ method = "GET", path: apiPath, params = {}, data = {}, skipToken = false }) { |
| 164 | const options = { |
| 165 | method, |
| 166 | url: `${API_BASE}${apiPath.startsWith("/") ? apiPath : `/${apiPath}`}`, |
| 167 | headers: this.getHeaders(method === "POST" ? { "Content-Type": "application/json" } : {}), |
| 168 | timeout: 15000, |
| 169 | validateStatus: () => true, |
| 170 | }; |
| 171 | options.params = skipToken ? params : this.getBaseParams(params); |
| 172 | if (method !== "GET") options.data = data; |
| 173 | |
| 174 | const { data: result, status, headers } = await axios.request(options); |
| 175 | if (headers["set-cookie"]) { |
| 176 | this.cookie = headers["set-cookie"].map((item) => item.split(";")[0]).join("; "); |
| 177 | } |
| 178 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 179 | if (!result || result.code !== 0) throw new Error(result?.msg || JSON.stringify(result)); |
| 180 | return result.data; |
| 181 | } |
| 182 | |
| 183 | async getLoginCode() { |
| 184 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected