(path, options = {})
| 1720 | } |
| 1721 | |
| 1722 | async function api(path, options = {}) { |
| 1723 | if (DEMO_MODE) return demoApi(path, options); |
| 1724 | const response = await fetch(path, { |
| 1725 | headers: { "Content-Type": "application/json" }, |
| 1726 | ...options |
| 1727 | }); |
| 1728 | const data = await response.json(); |
| 1729 | if (!data.ok) { |
| 1730 | const error = new Error(data.error || ui().common.requestFailed); |
| 1731 | error.status = response.status; |
| 1732 | error.path = path; |
| 1733 | error.payload = data; |
| 1734 | throw error; |
| 1735 | } |
| 1736 | return data; |
| 1737 | } |
| 1738 | |
| 1739 | function isUnknownApiRoute(error, route = "") { |
| 1740 | return Number(error?.status) === 404 |
no test coverage detected