({ method = "GET", apiPath, query = {}, data = {} })
| 148 | } |
| 149 | |
| 150 | async request({ method = "GET", apiPath, query = {}, data = {} }) { |
| 151 | const options = { |
| 152 | method, |
| 153 | url: this.buildUrl(apiPath, query), |
| 154 | headers: this.getHeaders(method === "POST" ? { "Content-Type": "application/json" } : {}), |
| 155 | timeout: 15000, |
| 156 | validateStatus: () => true, |
| 157 | }; |
| 158 | if (method !== "GET") options.data = data; |
| 159 | |
| 160 | const { status, data: result } = await axios.request(options); |
| 161 | if (status !== 200) throw new Error(`HTTP ${status}: ${typeof result === "string" ? result.slice(0, 200) : JSON.stringify(result)}`); |
| 162 | if (!result || result.code !== 0) { |
| 163 | const err = new Error(result?.msg || result?.message || JSON.stringify(result)); |
| 164 | err.code = result?.code; |
| 165 | throw err; |
| 166 | } |
| 167 | return result.data; |
| 168 | } |
| 169 | |
| 170 | async getWxCode() { |
| 171 | const wxServerUrl = process.env.wx_server_url; |
no test coverage detected