2016-12-14 70 views
0

我在app.js错误招摇快车兆瓦处理

'use strict'; 

var SwaggerExpress = require('swagger-express-mw'); 
var app = require('express')(); 
module.exports = app; // for testing 

var config = { 
    appRoot: __dirname // required config 
}; 

SwaggerExpress.create(config, function(err, swaggerExpress) { 
    console.log("Web Server started."); 

    if (err) { throw err; } 

    // install middleware 
    swaggerExpress.register(app); 
    app.use(function(err, req, res, next) { 
    console.log('caught it!'); 
    dosomething(); 
    }); 
    var port = process.env.PORT || 10010; 
    app.listen(port); 

}); 

我的控制器hello_world.js

function hello(req, res) { 
    throw new Error('my error!'); 
} 

下面的代码时,我启动应用程序和浏览器http://localhost:10010/hello ,如预期的那样,这返回500错误消息。但是,错误处理中间件根本没有被调用。有任何想法吗?

回答

1

如果您从default.yaml删除默认配件,它将起作用。

  • 的onError:json_error_handler