2016-12-14 71 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