({ method = "GET", apiPath, params = {}, data = {}, notAuth = false })
| 144 | } |
| 145 | |
| 146 | async request({ method = "GET", apiPath, params = {}, data = {}, notAuth = false }) { |
| 147 | const upperMethod = method.toUpperCase(); |
| 148 | const options = { |
| 149 | method: upperMethod, |
| 150 | url: `${API_BASE}${apiPath.startsWith("/") ? apiPath : `/${apiPath}`}`, |
| 151 | headers: this.getHeaders(notAuth ? { Authorization: "none" } : {}), |
| 152 | timeout: 20000, |
| 153 | validateStatus: () => true, |
| 154 | }; |
| 155 | if (upperMethod === "GET") options.params = params; |
| 156 | else options.data = data; |
| 157 | |
| 158 | const { data: result, status } = await axios.request(options); |
| 159 | if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`); |
| 160 | if (!result || (Number(result.code) !== 200 && String(result.code) !== "200")) { |
| 161 | throw new Error(result?.msg || result?.message || JSON.stringify(result)); |
| 162 | } |
| 163 | return result.data; |
| 164 | } |
| 165 | |
| 166 | async getLoginCode() { |
| 167 | const { data } = await wechat.getCode(this.account); |
no test coverage detected