From 078d79aa151b62165986d12a3aa2304b3d1c16bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20Dahl=C3=A9n?= <85930202+kickster97@users.noreply.github.com> Date: Tue, 5 Sep 2023 09:49:09 +0200 Subject: [PATCH] return bool is_error with http response (#558) * let the HTTP request function return an error with boolean is_error so the toasts can be shown correctly even when there is no return value from the backend --- static/js/http.js | 4 ++-- static/js/queues.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/static/js/http.js b/static/js/http.js index a80a5e75c6..be0d7f6a17 100644 --- a/static/js/http.js +++ b/static/js/http.js @@ -15,9 +15,9 @@ function request (method, path, options = {}) { return window.fetch(path, opts) .then(response => { if (!response.ok) { - const error = { status: response.status, reason: response.statusText } + const error = { status: response.status, reason: response.statusText, is_error: true } return response.json() - .then(json => { error.reason = json.reason }) + .then(json => { error.reason = json.reason; return error }) .finally(() => { standardErrorHandler(error) }) } else { return response.json().catch(() => null) } }) diff --git a/static/js/queues.js b/static/js/queues.js index 8f54b5f870..290d61a1dd 100644 --- a/static/js/queues.js +++ b/static/js/queues.js @@ -125,7 +125,8 @@ document.querySelector('#declare').addEventListener('submit', function (evt) { arguments: Dom.parseJSON(data.get('arguments')) } HTTP.request('PUT', url, { body }) - .then(() => { + .then((response) => { + if (response?.is_error) { return } queuesTable.reload() evt.target.reset() Dom.toast('Queue ' + queue + ' created')