diff --git a/cmd/api/config.go b/cmd/api/config.go index ad2f2e78..137ab883 100644 --- a/cmd/api/config.go +++ b/cmd/api/config.go @@ -9,11 +9,16 @@ import ( ) func configHandler(w http.ResponseWriter, r *http.Request) { + if app.ConfigPath == "" { + http.Error(w, "", http.StatusGone) + return + } + switch r.Method { case "GET": data, err := os.ReadFile(app.ConfigPath) if err != nil { - http.NotFound(w, r) + http.Error(w, "", http.StatusNotFound) return } if _, err = w.Write(data); err != nil { diff --git a/www/editor.html b/www/editor.html index 8765b966..605d3ad0 100644 --- a/www/editor.html +++ b/www/editor.html @@ -41,7 +41,7 @@ method: 'POST', body: editor.getValue() }).then(r => { if (r.ok) { - alert("OK"); + alert('OK'); fetch('api/exit', {method: 'POST'}); } else { r.text().then(alert); @@ -50,8 +50,18 @@ }); window.addEventListener('load', () => { - fetch('api/config').then(r => r.text()).then(data => { - editor.setValue(data); + fetch('api/config', {cache: 'no-cache'}).then(r => { + if (r.status === 410) { + alert('Config file is not set'); + } else if (r.status === 404) { + editor.setValue(''); // config file not exist + } else if (r.ok) { + r.text().then(data => { + editor.setValue(data); + }); + } else { + alert(`Unknown error: ${r.statusText} (${r.status})`); + } }); })