diff options
Diffstat (limited to 'public/gallery.js')
-rw-r--r-- | public/gallery.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/public/gallery.js b/public/gallery.js index 299d372..9d3b067 100644 --- a/public/gallery.js +++ b/public/gallery.js @@ -1,14 +1,25 @@ 'use strict' +let callActive = false +let callFaulty = false + function call(method, params) { - // TODO: Make it apparent when results result in errors: - // - With responseType == "json", m.request() always expects JSON, - // and error.message is null if it fails, but we can handle it manually. - // - Go can wrap all errors into trivial strings before writing. + // XXX: At least with POST, unsuccessful requests result + // in catched errors containing Errors with a null message. + // This is an issue within XMLHttpRequest. + callActive++ return m.request({ method: "POST", url: `/api/${method}`, body: params, + }).then(result => { + callActive-- + callFaulty = false + return result + }).catch(error => { + callActive-- + callFaulty = true + throw error }) } @@ -72,8 +83,11 @@ let Header = { return m('.header', {}, [ m('nav', main), m('nav', context), - // TODO: End it with an activity indicator. - m('.activity', '☺'), + callFaulty + ? m('.activity.error[title=Error]', '●') + : callActive + ? m('.activity[title=Busy]', '●') + : m('.activity[title=Idle]', '○'), ]) }, } |