(method, path, data = {}, headers = {})
| 139 | } |
| 140 | |
| 141 | async api(method, path, data = {}, headers = {}) { |
| 142 | const { status, data: result } = await request({ |
| 143 | method, |
| 144 | url: `${API_BASE}${path}`, |
| 145 | params: method.toUpperCase() === "GET" ? data : undefined, |
| 146 | data: method.toUpperCase() === "GET" ? undefined : data, |
| 147 | headers: { |
| 148 | ...(this.token ? { Authorization: `Bearer ${this.token}` } : {}), |
| 149 | ...headers, |
| 150 | }, |
| 151 | }); |
| 152 | if (status !== 200) throw new Error(`${path} HTTP ${status}: ${short(result)}`); |
| 153 | return result; |
| 154 | } |
| 155 | |
| 156 | assertOk(data, name) { |
| 157 | if (Number(data?.code) !== 0) throw new Error(`${name}失败: ${short(data)}`); |
no test coverage detected