(
path: string,
params?: Record<string, string>,
)
| 102 | // ---- Helpers -------------------------------------------------------- |
| 103 | |
| 104 | private async get<T>( |
| 105 | path: string, |
| 106 | params?: Record<string, string>, |
| 107 | ): Promise<T> { |
| 108 | const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/'; |
| 109 | const url = new URL(path.startsWith('/') ? path.slice(1) : path, base); |
| 110 | if (params) { |
| 111 | for (const [k, v] of Object.entries(params)) { |
| 112 | if (v !== undefined && v !== '') url.searchParams.set(k, v); |
| 113 | } |
| 114 | } |
| 115 | const res = await fetch(url.toString()); |
| 116 | if (!res.ok) { |
| 117 | const body = await res.text().catch(() => ''); |
| 118 | throw new Error(`Server error ${res.status}: ${body}`); |
| 119 | } |
| 120 | return res.json() as Promise<T>; |
| 121 | } |
| 122 | |
| 123 | private async post<T>(path: string, body: unknown): Promise<T> { |
| 124 | const base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/'; |
no test coverage detected