Don't crash ST server on invalid streaming URL

This commit is contained in:
Cohee
2023-10-08 23:42:28 +03:00
parent 54d52a2986
commit d265179f46
2 changed files with 28 additions and 2 deletions

View File

@@ -552,8 +552,18 @@ app.post("/generate_textgenerationwebui", jsonParser, async function (request, r
});
async function* readWebsocket() {
const streamingUrl = new URL(streamingUrlString);
const websocket = new WebSocket(streamingUrl);
/** @type {WebSocket} */
let websocket;
/** @type {URL} */
let streamingUrl;
try {
const streamingUrl = new URL(streamingUrlString);
websocket = new WebSocket(streamingUrl);
} catch (error) {
console.log("[SillyTavern] Socket error", error);
return;
}
websocket.on('open', async function () {
console.log('WebSocket opened');