| 71 | status.textContent = ''; |
| 72 | }; |
| 73 | const request = async (url, payload, signal) => { |
| 74 | const response = await fetch(OC.generateUrl(url), { |
| 75 | method: 'POST', headers: OCA.Analytics.headers(), signal, |
| 76 | body: JSON.stringify(payload) |
| 77 | }); |
| 78 | let result; |
| 79 | try { result = await response.json(); } |
| 80 | // TRANSLATORS: {status} is an HTTP response status code, e.g. 404. |
| 81 | catch (error) { throw new Error(t('analytics', 'The datasource request failed (HTTP {status}).', {status: response.status})); } |
| 82 | if (!response.ok || (result.error && String(result.error) !== '0')) { |
| 83 | throw new Error(result.error || t('analytics', 'Could not load JSON data. Check the datasource settings.')); |
| 84 | } |
| 85 | return result; |
| 86 | }; |
| 87 | previewButton.addEventListener('click', async () => { |
| 88 | previewController?.abort(); |
| 89 | previewController = new AbortController(); |