mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: catch websocket errors
This commit is contained in:
1 parent
62ce66237a
commit
00f83d805a
1 file changed
+6
@@ -497,6 +497,12 @@ ${ctx.response.status} ${endTime - startTime}ms ${ctx.response.length}`);
|
|||||||
layers.forEach((layer) => app.use(layer as any));
|
layers.forEach((layer) => app.use(layer as any));
|
||||||
app.use((ctx) => handle(ctx, NotFoundHandler, () => true));
|
app.use((ctx) => handle(ctx, NotFoundHandler, () => true));
|
||||||
wsServer.on('connection', async (socket, request) => {
|
wsServer.on('connection', async (socket, request) => {
|
||||||
|
socket.on('error', (err) => {
|
||||||
|
logger.warn('Websocket Error: %s', err.message);
|
||||||
|
try {
|
||||||
|
socket.close(1003, 'Websocket Error');
|
||||||
|
} catch (e) { }
|
||||||
|
});
|
||||||
const ctx: any = app.createContext(request, {} as any);
|
const ctx: any = app.createContext(request, {} as any);
|
||||||
await domainLayer(ctx, () => baseLayer(ctx, () => layers[1](ctx, () => userLayer(ctx, () => { }))));
|
await domainLayer(ctx, () => baseLayer(ctx, () => layers[1](ctx, () => userLayer(ctx, () => { }))));
|
||||||
for (const manager of router.wsStack) {
|
for (const manager of router.wsStack) {
|
||||||
|
|||||||
Reference in new issue
Block a user