({ method = "POST", apiPath, params = {}, data = {}, skipToken = false })
| 138 | } |
| 139 | |
| 140 | async request({ method = "POST", apiPath, params = {}, data = {}, skipToken = false }) { |
| 141 | const options = { |
| 142 | method, |
| 143 | url: `${API_BASE}${apiPath}`, |
| 144 | headers: this.getHeaders(method === "POST" ? { "Content-Type": "application/json" } : {}), |
| 145 | timeout: 15000, |
| 146 | validateStatus: () => true, |
| 147 | }; |
| 148 | if (method === "GET") options.params = params; |
| 149 | else options.data = data; |
| 150 | if (skipToken) delete options.headers.Authorization; |
| 151 | |
| 152 | const { status, data: result } = await axios.request(options); |
| 153 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 154 | if (result && typeof result === "object" && result.error !== undefined && result.error !== 0) { |
| 155 | const err = new Error(result.errorMsg || result.msg || JSON.stringify(result)); |
| 156 | err.code = result.error; |
| 157 | throw err; |
| 158 | } |
| 159 | return result?.data ?? result; |
| 160 | } |
| 161 | |
| 162 | async getLoginCode() { |
| 163 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected