Drafts: Fix logic in JS when no draft available

This commit is contained in:
Anna Sidwell 2019-04-07 17:18:55 +01:00
parent 58b18dd815
commit c84de45b10

View File

@ -197,8 +197,11 @@ function initDrafts() {
if (!formHasErrors) { if (!formHasErrors) {
// Get the previous draft, if any // Get the previous draft, if any
apiGetDraft() apiGetDraft()
.then(response => response.json()) .then(response => {
.then(json => { if (response.status == 404) {
console.log("No draft stored on server");
} else if (response.ok) {
response.json().then(json => {
// Handle the case where we didn't get a response // Handle the case where we didn't get a response
if (!json) return if (!json) return
@ -207,7 +210,12 @@ function initDrafts() {
} }
showDraftPrompt(formSaver, json.data.form) showDraftPrompt(formSaver, json.data.form)
}).catch(err => { });
} else {
throw new Error("Error getting draft", response)
}
})
.catch(err => {
console.error(err); console.error(err);
}) })
} }