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) {
// Get the previous draft, if any
apiGetDraft()
.then(response => response.json())
.then(json => {
// Handle the case where we didn't get a response
if (!json) return
.then(response => {
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
if (!json) return
if (json.version !== 1) {
throw new Error("Bad JSON response version")
if (json.version !== 1) {
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);
})
}