Closed UchihaVeha closed 5 years ago
const middleware = (ctx, next) => { const { accessToken } = ctx.socket.socket.handshake.query; try { const { id } = jwt.verify( accessToken, config.auth.jwt.accessTokenSecretKey ); ctx.userId = id; await next(); } catch (err) { let error = 'internal error'; if (err instanceof jwt.JsonWebTokenError) { error = 'authentication error'; } if (ctx.acknowledge) { ctx.acknowledge({ success: false, error }); } } } chat.on(MESSAGES_FETCH_REQUEST, async ctx => { const payload = await Messages.findAll(ctx.data); ctx.acknowledge({ success: true, payload }); });
If some error happen in Messages.findAll(ctx.data), it doesn't appear in catch block of middleware because this in Socket:
this.middleware( packet, () => { handler( packet, data ); });
if i replace on that, all work fine:
this.middleware( packet, () => handler( packet, data ));
I just think you forgot to returning data from event handler?
If some error happen in Messages.findAll(ctx.data), it doesn't appear in catch block of middleware because this in Socket:
if i replace on that, all work fine:
I just think you forgot to returning data from event handler?