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) {
// Get the previous draft, if any
apiGetDraft()
.then(response => response.json())
.then(json => {
.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
@ -207,7 +210,12 @@ function initDrafts() {
}
showDraftPrompt(formSaver, json.data.form)
}).catch(err => {
});
} else {
throw new Error("Error getting draft", response)
}
})
.catch(err => {
console.error(err);
})
}