(path, options = {})
| 253 | } |
| 254 | |
| 255 | async function api(path, options = {}) { |
| 256 | if (DEMO_MODE) { |
| 257 | return demoApi(path, options); |
| 258 | } |
| 259 | const response = await fetch(path, { |
| 260 | headers: { "Content-Type": "application/json" }, |
| 261 | ...options, |
| 262 | }); |
| 263 | const data = await response.json(); |
| 264 | if (!response.ok || !data.ok) { |
| 265 | throw new Error(localizeError(data.error || `Request failed: ${path}`)); |
| 266 | } |
| 267 | return data; |
| 268 | } |
| 269 | |
| 270 | function parseDemoBody(options) { |
| 271 | if (!options || !options.body) return {}; |
no test coverage detected