After asking this question, I've found that I can add a callback array to an endpoint in a sails app like this:
file: /api/policies/somepolicy.js
module.exports = thisIsAnArrayOfCallbacks;
This works ok while each member of thisIsAnArrayOfCallbacks
is a function
which accepts req
, res
, and next
as arguments. The controller call executes all the functions in the array and the expected result is obtained in a normal flow.
But when using an errorHandler
callback (like the one in this example) which takes an additional err
parameter, it doesn't work as expected: the express-only version app.get('/path', thisIsAnArrayOfCallbacks)
allows the errorHandler
to fetch the exception and report a proper response to the client, but when using the sails way, the errorHandler
function isn't called and the exception is thrown in the response.
How could I fetch the err
parameter or catch the exception occurred in one of the functions of thisIsAnArrayOfCallbacks
to send a proper response (a custom one is preferred) to the client?
Thanks in advance.