ui: handle WebSocket 403 unauthorized errors properly

When WebSocket connection fails due to 403 unauthorized status from server,
browser WebSocket API cannot distinguish HTTP status codes and only fires
a generic 'error' event. Redirect to /connect/:devid HTTP endpoint so that
browser can properly capture and handle the 403 status code response.

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2025-07-16 17:05:17 +08:00
parent 3842518da9
commit 0ca0086bdd
+6 -1
View File
@@ -267,7 +267,12 @@ export default {
}
})
socket.addEventListener('error', () => this.closed())
socket.addEventListener('error', () => {
let href = `/connect/${this.devid}`
if (group)
href += `?group=${group}`
window.location.href = href
})
socket.addEventListener('message', ev => {
const data = ev.data