chat2web frontend: wrap JSON.parse()s in try-catch blocks
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({ channel: event.target.value })
|
body: JSON.stringify({ channel: event.target.value })
|
||||||
});
|
});
|
||||||
const content = await rawResponse.json();
|
// const content = await rawResponse.json();
|
||||||
// TODO: use the response
|
// TODO: use the response
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({ message: message })
|
body: JSON.stringify({ message: message })
|
||||||
});
|
});
|
||||||
const content = await rawResponse.json();
|
// const content = await rawResponse.json();
|
||||||
// TODO: use the response
|
// TODO: use the response
|
||||||
|
|
||||||
this.elements.chatInput.value = '';
|
this.elements.chatInput.value = '';
|
||||||
@@ -123,8 +123,6 @@
|
|||||||
if (scrolledToBottom) {
|
if (scrolledToBottom) {
|
||||||
liMessage.scrollIntoView();
|
liMessage.scrollIntoView();
|
||||||
}
|
}
|
||||||
// // just to update this.scrolledToBottom
|
|
||||||
// this.messagesAreScrolledToBottom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAllMessages() {
|
clearAllMessages() {
|
||||||
@@ -140,30 +138,42 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.sse.addEventListener('switch-channel', (event) => {
|
this.sse.addEventListener('switch-channel', (event) => {
|
||||||
// TODO: error handling
|
try {
|
||||||
this.updateChannelHint(JSON.parse(event.data).channel);
|
this.updateChannelHint(JSON.parse(event.data).channel);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// new messages to be appended to the message list
|
// new messages to be appended to the message list
|
||||||
this.sse.addEventListener('new-message', (event) => {
|
this.sse.addEventListener('new-message', (event) => {
|
||||||
// TODO: error handling
|
try {
|
||||||
for (const message of JSON.parse(event.data).messages) {
|
for (const message of JSON.parse(event.data).messages) {
|
||||||
this.addMessage(message);
|
this.addMessage(message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// a bulk of new messages, with a clear of the message list beforehand
|
// a bulk of new messages, with a clear of the message list beforehand
|
||||||
this.sse.addEventListener('bulk-messages', (event) => {
|
this.sse.addEventListener('bulk-messages', (event) => {
|
||||||
this.clearAllMessages();
|
this.clearAllMessages();
|
||||||
// TODO: error handling
|
try {
|
||||||
for (const message of JSON.parse(event.data).messages) {
|
for (const message of JSON.parse(event.data).messages) {
|
||||||
this.addMessage(message);
|
this.addMessage(message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.sse.addEventListener('channel-list', (event) => {
|
this.sse.addEventListener('channel-list', (event) => {
|
||||||
// TODO: error handling
|
try {
|
||||||
this.updateChannels(JSON.parse(event.data).channels);
|
this.updateChannels(JSON.parse(event.data).channels);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user