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,17 +197,25 @@ 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) {
// Handle the case where we didn't get a response console.log("No draft stored on server");
if (!json) return } else if (response.ok) {
response.json().then(json => {
// Handle the case where we didn't get a response
if (!json) return
if (json.version !== 1) { if (json.version !== 1) {
throw new Error("Bad JSON response version") throw new Error("Bad JSON response version")
}
showDraftPrompt(formSaver, json.data.form)
});
} else {
throw new Error("Error getting draft", response)
} }
})
showDraftPrompt(formSaver, json.data.form) .catch(err => {
}).catch(err => {
console.error(err); console.error(err);
}) })
} }