mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 09:13:08 +02:00
fix(server): Prevent error when recieve non-json data from websocket
Fix #6658
This commit is contained in:
parent
48e8ee440b
commit
0ace009a54
1 changed files with 9 additions and 1 deletions
|
@ -71,7 +71,15 @@ export default class Connection {
|
||||||
private async onWsConnectionMessage(data: websocket.IMessage) {
|
private async onWsConnectionMessage(data: websocket.IMessage) {
|
||||||
if (data.utf8Data == null) return;
|
if (data.utf8Data == null) return;
|
||||||
|
|
||||||
const { type, body } = JSON.parse(data.utf8Data);
|
let obj: Record<string, any>;
|
||||||
|
|
||||||
|
try {
|
||||||
|
obj = JSON.parse(data.utf8Data);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { type, body } = obj;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'api': this.onApiRequest(body); break;
|
case 'api': this.onApiRequest(body); break;
|
||||||
|
|
Loading…
Reference in a new issue