Skip to content

Commit

Permalink
return bool is_error with http response (#558)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kickster97 authored Sep 5, 2023
1 parent a746e30 commit 078d79a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions static/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
})
Expand Down
3 changes: 2 additions & 1 deletion static/js/queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 078d79a

Please sign in to comment.