balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

Express error middleware doesn't seem to be used #7006

Open strugee opened 4 years ago

strugee commented 4 years ago

Node version: 10.21.0 Sails version (sails): 1.2.4 ORM hook version (sails-hook-orm): 2.1.1 Sockets hook version (sails-hook-sockets): not installed, although there are some lingering bits from when it was Organics hook version (sails-hook-organics): not installed Grunt hook version (sails-hook-grunt): 4.0.0 Uploads hook version (sails-hook-uploads): not installed DB adapter & version (e.g. sails-mysql@5.55.5): sails-postgresql@1.0.2 (though I've been reproducing this using sails-disk in development) Skipper adapter & version (e.g. skipper-s3@5.55.5): not installed (I think?)


Given the following in config/http.js:

  middleware: {
     order: [
       'cookieParser',
       'session',
       'bodyParser',
       'compress',
       'poweredBy',
       'router',
       'www',
       'favicon',
       'testError'
     ],

    testError: function(err, req, res, next) {
      sails.log.error('Test error');
      throw new Error('test error');
    }
  }

Any HTTP 500 error seems like it should cause Test error to be logged to the console, followed by an additional test error stack trace. But I don't see anything.

Am I meant to be using https://sailsjs.com/documentation/reference/response-res/res-server-error? This would probably work but feels wrong - for context, what I'm really trying to do is use Sentry's Express integration in my Sails app. So what I care about is not 500 errors per se, but instead just any error generated during request processing (though I admit that in the end for almost all apps these turn into 500 errors anyway). The middleware ordering also matters; I need this error middleware to be run before any other error middleware.

sailsbot commented 4 years ago

@strugee Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

strugee commented 4 years ago
* Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails.  But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.

Also as a P.S. to my bug report: thank you for maintaining Sails <3

I've just started using it after using bare Express for a long time and I gotta say, I'm starting to really like it.

eashaw commented 4 years ago

Hi @strugee, thank you for your interest in Sails

Am I meant to be using https://sailsjs.com/documentation/reference/response-res/res-server-error?

YES! If you want to handle non 5XX errors, stick that in all of your custom response files (how you do this will affect the order)