diff options
| author | 2025-11-05 11:46:46 +0100 | |
|---|---|---|
| committer | 2025-11-05 11:46:46 +0100 | |
| commit | 0587ccaff844701b08306440c96c89cefa21b2c9 (patch) | |
| tree | 77b9a0841c84f3f8f91eddb696f01c8bcc744201 /p | |
| parent | 6fb2044563db9019780d622c9c9459f0f7fd20fe (diff) | |
Custom favicons async/await (#8182)
Rewrote the last Promise pattern of our code-base with an async/await pattern: [custom feed favicons](https://github.com/FreshRSS/FreshRSS/pull/7646)
Related to:
* https://github.com/FreshRSS/FreshRSS/pull/7962
Diffstat (limited to 'p')
| -rw-r--r-- | p/scripts/extra.js | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/p/scripts/extra.js b/p/scripts/extra.js index 2e956d6db..96874a65d 100644 --- a/p/scripts/extra.js +++ b/p/scripts/extra.js @@ -249,26 +249,27 @@ function init_update_feed() { }); if (faviconExtBtn) { - faviconExtBtn.onclick = function (e) { + faviconExtBtn.onclick = async function (e) { e.preventDefault(); faviconExtBtn.disabled = true; - fetch(faviconExtBtn.dataset.extensionUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json; charset=utf-8' - }, - body: JSON.stringify({ - '_csrf': context.csrf, - 'extAction': 'query_icon_info', - 'id': +feed_update.dataset.feedId - }), - }).then(resp => { + try { + const resp = await fetch(faviconExtBtn.dataset.extensionUrl, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: JSON.stringify({ + '_csrf': context.csrf, + 'extAction': 'query_icon_info', + 'id': +feed_update.dataset.feedId + }), + }); if (!resp.ok) { faviconExtBtn.disabled = false; - return Promise.reject(resp); + throw new Error(`Custom favicons HTTP error ${resp.status}: ${resp.statusText}`); } - return resp.json(); - }).then(json => { + const json = await resp.json(); clearUploadedIcon(); const resetField = feed_update.querySelector('input[name="resetFavicon"]'); if (resetField) { @@ -281,7 +282,9 @@ function init_update_feed() { extension.dataset.initialExt = extension.innerText; extension.innerText = json.extName; favicon.src = json.iconUrl; - }); + } catch (error) { + faviconExtBtn.disabled = false; + } }; faviconExtBtn.form.onsubmit = async function (e) { const extChanged = faviconExtBtn.disabled; |
