(path, payload)
| 47 | } |
| 48 | |
| 49 | async function apiPost(path, payload) { |
| 50 | const resp = await fetch(withBase(path), { |
| 51 | method: 'POST', |
| 52 | credentials: 'include', |
| 53 | headers: { |
| 54 | 'Content-Type': 'application/json', |
| 55 | 'X-CSRF-Token': csrfToken(), |
| 56 | Accept: 'application/json' |
| 57 | }, |
| 58 | body: JSON.stringify(payload || {}) |
| 59 | }); |
| 60 | |
| 61 | const body = await safeJson(resp); |
| 62 | if (!resp.ok || !body || body.ok === false) { |
| 63 | throw new Error((body && (body.error || body.message || body.assistant)) || `HTTP ${resp.status}`); |
| 64 | } |
| 65 | return body; |
| 66 | } |
| 67 | |
| 68 | function makeEl(tag, attrs = {}, html = '') { |
| 69 | const el = document.createElement(tag); |
no test coverage detected