apigee-127 / swagger-node-runner

The heart of Swagger-Node
MIT License
102 stars 124 forks source link

Respond with error in hapi middleware #86

Open dave-irvine opened 7 years ago

dave-irvine commented 7 years ago

Hi,

I can't find any documentation that tells me how to reply with an error when using the hapi middleware. Ideally I would use Boom, as this is what I am used to with hapi.

Usually my route handler would look like:

function (request, reply) {
        return reply(Boom.badRequest('Unsupported parameter'));
}

however with swagger-node-runner my route handlers have to be of the req,res variety, which has no Boom integration.

I suppose I could do

res.status(400).send('Unsuported parameter');

but that kind of negates the usefulness of Boom.

Any ideas?

dave-irvine commented 7 years ago

Turns out I can't do

res.status(400).send('Unsupported parameter');

because the middleware is not chainable like express. It's a confusing mashup of the two.

dave-irvine commented 7 years ago
res.statusCode = 400;
res.end({
  message: 'Unsupported parameter',
});

works, but is quite ugly.