question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware error not catches

See original GitHub issue

I might be making a mistake, but I cannot manage to catch middleware error on client, here is server code:

(function () {
    'use strict';

    var url = require("url"),
        sio = require('socket.io')(3010);

    //Authentification required
    sio.use(function (socket, next) {
        return next(new Error('refused client'));
    });
}());

and client code:

(function () {
    "use strict";

    //Network
    var socket = io.connect(SOCKET_IO_SERVER);

    socket.on('error', function(){
        console.error(arguments);
    });
}());

So is it a bug ?

EDIT: Using network tab on chrome I do see a polling request containing “refused client”

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jbaezcommented, Nov 2, 2016

I have the same issue when using namespaces. @oliveiragabriel07 solution worked for me as well but I think the client should be able to receive an error thrown in the general connection middelware ( io.use ) I guess this is a socket.io server issue

3reactions
oliveiragabriel07commented, Jan 19, 2015

+1 Error callback is not beeing called on client side when Error is passed as parameter to next on middleware.

Edit

I found that when using namespaces, the middleware should be attached to the namespace:

var nsp = io.of('/namespace');

// client never receives the error event
io.use(function (socket, next) {
    return next(new Error('refused client')); 
});

// this way works
nsp.use(function (socket, next) {
    return next(new Error('refused client')); 
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception handler middleware not catching - Stack Overflow
My solution to this problem was to remove app.UseDeveloperExceptionPage(); in Startup.cs.
Read more >
Error handling - Express.js
It's important to ensure that Express catches all errors that occur while running route handlers and middleware. Errors that occur in synchronous code ......
Read more >
Handle errors in ASP.NET Core | Microsoft Learn
The status code pages middleware does not catch exceptions. To provide a custom error handling page, use the exception handler page.
Read more >
A Guide to Error Handling in Express.js | Scout APM Blog
Note: Express 5.0 (currently in alpha) can automatically catch errors (and rejections) thrown by returned Promises. Handling Custom Errors.
Read more >
Error Handling in Express - Reflectoring
We are intercepting the error in a catch block and returning an error message with an error code of 500 in the HTTP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found