(apiPath, data = {}, options = {})
| 124 | } |
| 125 | |
| 126 | async request(apiPath, data = {}, options = {}) { |
| 127 | const token = options.noauth ? GUEST_TOKEN : (this.session.token || GUEST_TOKEN); |
| 128 | const res = await axios.post(`${API_BASE}${apiPath}`, formBody({ |
| 129 | ...(data || {}), |
| 130 | token, |
| 131 | }), { |
| 132 | headers: this.headers(), |
| 133 | timeout: 20000, |
| 134 | validateStatus: () => true, |
| 135 | }); |
| 136 | |
| 137 | if (res.status !== 200) throw new Error(`HTTP ${res.status}`); |
| 138 | if (Number(res.data?.code) !== 1000) { |
| 139 | const error = new Error(res.data?.msg || `接口错误: ${res.data?.code || "unknown"}`); |
| 140 | error.data = res.data; |
| 141 | throw error; |
| 142 | } |
| 143 | return res.data; |
| 144 | } |
| 145 | |
| 146 | async getLoginCode() { |
| 147 | const { data } = await wechat.getCode(this.openid); |
no test coverage detected