Error handling in socket.use 3.x versions #3865
-
Hello! In the architecture of my project, there are public methods that do not require access, which are mixed with methods that require access. Examples methods on client-side: socket.emit('api.version', console.log); // public
socket.emit('events.get', console.log); // private In 2.x versions there was a method I could check if the method is public, because in each request I could get the method name. Like this: io.on('connection', (socket) => {
socket.use((packet, next) => {
if (packet[0]) {
const methodName = packet[0];
const isPublicMethod = [
'api.schema',
'api.version',
].includes(methodName);
if ( ! isPublicMethod) return next(new Error('Need API key!'));
else next();
}
}); How can I do this in 3.x versions? This code is not working, I am getting an error: "Missing error handler on In method For example, there is a method |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! I've updated the documentation here: https://socket.io/docs/v4/server-socket-instance/#Socket-middlewares Could you please check if that's clear enough? |
Beta Was this translation helpful? Give feedback.
Hi! I've updated the documentation here: https://socket.io/docs/v4/server-socket-instance/#Socket-middlewares
Could you please check if that's clear enough?