Thursday 20 April 2017

error middleware in azure-mobile-apps-node

I want to catch errors from api folder.

However, the express error handling middleware catch nothing unless the errors triggered from any handler declared using standard express routing app.get(someroute,handler)

Any suggestions on this?

Thanks in advance.

app.js

mobile.api.import('./api');
mobile.tables.initialize()
    .then(function () {
        app.use(mobile);    // Register the Azure Mobile Apps middleware
        app.listen(process.env.PORT || 3000);   // Listen for requests
    })
    .then(function(){
        if (process.env.NODE_ENV == 'production'){
            ///handle errors on prod
            app.use(function(err, req, res, next) {
                console.log('error catch - here');
                res.statusCode = 500;
                res.end();
            });
        }
    });

api/testing.js

module.exports = {
    "get": function (req, res, next) {
        throw new Error('this is error');
    }
};



via RYT

No comments:

Post a Comment