(action: string, params = {})
| 59 | } |
| 60 | |
| 61 | async call(action: string, params = {}) { |
| 62 | try { |
| 63 | await Promise.resolve(this.loginP); |
| 64 | console.log('正在调用服务:', action); |
| 65 | const { data } = await this.request.post( |
| 66 | '/api/' + action.replace(/\./g, '/'), |
| 67 | params |
| 68 | ); |
| 69 | |
| 70 | return data; |
| 71 | } catch (err: any) { |
| 72 | console.error('服务调用失败:', err); |
| 73 | const data: string = err?.response?.data; |
| 74 | if (data) { |
| 75 | throw new Error( |
| 76 | JSON.stringify({ |
| 77 | action, |
| 78 | data, |
| 79 | }) |
| 80 | ); |
| 81 | } else { |
| 82 | throw err; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | async whoami() { |
| 88 | return this.call('user.whoami'); |
no test coverage detected