vbn
vbn

Reputation: 799

Error handling in swagger-express-mw

I have the following code in my 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);

});

And my controller hello_world.js

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

When i start the app and browser to http://localhost:10010/hello, this returns a 500 response with my error message as expected. However, the error handling middleware didn't get called at all. Any ideas?

Upvotes: 1

Views: 2067

Answers (1)

Michael Sync
Michael Sync

Reputation: 5014

if you remove the default fitting from default.yaml, it will work.

  • onError: json_error_handler

Upvotes: 4

Related Questions