slightly improved error handling

This commit is contained in:
James Shiffer 2020-06-22 12:04:26 -07:00
parent 9f2b80a924
commit b4e383a09c
No known key found for this signature in database
GPG Key ID: C0DB8774A1B3BA45
2 changed files with 6 additions and 1 deletions

View File

@ -73,7 +73,11 @@
body: JSON.stringify({ html, image, title, category }) body: JSON.stringify({ html, image, title, category })
}); });
const json = await res.json(); const json = await res.json();
goto(`/a/${json.slug}`); if (res.status === 200) {
goto(`/a/${json.slug}`);
} else {
alert(`Error ${res.status}: ${json.message}`);
}
} }
async function addCategory() async function addCategory()

View File

@ -254,6 +254,7 @@ express()
res.end(JSON.stringify({ res.end(JSON.stringify({
message: `You must supply a category name.` message: `You must supply a category name.`
})); }));
return;
} }
const cat = await new Category({ name }); const cat = await new Category({ name });
await cat.save(); await cat.save();