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