guard text.js node fetch on non-ok response
This commit is contained in:
parent
33668e2930
commit
17ab181adb
1 changed files with 8 additions and 1 deletions
|
|
@ -32,8 +32,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
function fetchAndRenderNodes(textId) {
|
function fetchAndRenderNodes(textId) {
|
||||||
return fetch('/api/nodes/' + textId, { credentials: 'same-origin' })
|
return fetch('/api/nodes/' + textId, { credentials: 'same-origin' })
|
||||||
.then(res => res.json())
|
.then(function (response) {
|
||||||
|
if (!response.ok) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
.then(nodes => {
|
.then(nodes => {
|
||||||
|
if (!Array.isArray(nodes)) return;
|
||||||
|
|
||||||
const existing = document.querySelector('#text-detail > ul');
|
const existing = document.querySelector('#text-detail > ul');
|
||||||
if (existing) existing.remove();
|
if (existing) existing.remove();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue