({ method = "GET", apiPath, data = {}, params = {}, needToken = true })
| 133 | } |
| 134 | |
| 135 | async request({ method = "GET", apiPath, data = {}, params = {}, needToken = true }) { |
| 136 | const options = { |
| 137 | method, |
| 138 | url: `${API_BASE}${apiPath}`, |
| 139 | headers: this.headers(needToken), |
| 140 | timeout: 15000, |
| 141 | validateStatus: () => true, |
| 142 | }; |
| 143 | if (method.toUpperCase() === "GET") options.params = params; |
| 144 | else options.data = data; |
| 145 | |
| 146 | const { status, data: result } = await axios.request(options); |
| 147 | if (status !== 200) throw new Error(`HTTP ${status}: ${typeof result === "string" ? result.slice(0, 200) : JSON.stringify(result)}`); |
| 148 | if (result && Object.prototype.hasOwnProperty.call(result, "error") && Number(result.error) !== 0) { |
| 149 | const err = new Error(result.errorMsg || result.error_msg || result.message || JSON.stringify(result)); |
| 150 | err.code = result.error; |
| 151 | throw err; |
| 152 | } |
| 153 | return result; |
| 154 | } |
| 155 | |
| 156 | async getWxCode() { |
| 157 | const wxServerUrl = process.env.wx_server_url; |
no test coverage detected