({ method = "GET", apiPath, params = {}, data = {}, skipToken = false })
| 129 | } |
| 130 | |
| 131 | async request({ method = "GET", apiPath, params = {}, data = {}, skipToken = false }) { |
| 132 | const options = { |
| 133 | method, |
| 134 | url: `${API_BASE}${apiPath}`, |
| 135 | headers: this.getHeaders(method === "POST" ? { "Content-Type": "application/json" } : {}), |
| 136 | timeout: 15000, |
| 137 | validateStatus: () => true, |
| 138 | }; |
| 139 | if (method === "GET") options.params = params; |
| 140 | else options.data = data; |
| 141 | if (skipToken) delete options.headers.Authorization; |
| 142 | |
| 143 | const { status, data: result } = await axios.request(options); |
| 144 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 145 | if (!result || result.code !== 0) { |
| 146 | const message = result?.msg || result?.message || JSON.stringify(result); |
| 147 | const err = new Error(message); |
| 148 | err.code = result?.code; |
| 149 | throw err; |
| 150 | } |
| 151 | return result.data; |
| 152 | } |
| 153 | |
| 154 | async getLoginCode() { |
| 155 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected