trailsjs / trailpack-express

:package: Express Trailpack
MIT License
12 stars 15 forks source link

Joi Validation failure for Route should result in a 400 not a 500 #49

Closed scott-wyatt closed 8 years ago

scott-wyatt commented 8 years ago

Ref: Trailpack-router #61 Adding this issue so it is not forgotten about.

Essentially here's the problem: If I have a route, and I validate it's query.

{
    method: ['POST'],
    path: '/route/control',
    handler: 'RouteController.control',
    config: {
      validate: {
        query: joi.object().keys({
          type: joi.string().valid('negative','positive')
        })
      }
    }
  }

If the query type fails validation in this case type is not positive or negative, it should return a 400 (bad request) instead, it is returning 500 (server error).

Spec would say that this is a bad request and not a server error, a 400 response always means that it can return data about the failure to the end user while a 500 should be forbidden to return data to the end user.

scott-wyatt commented 8 years ago

Hmmm, it looks like there are tests for this. So perhaps I am just doing this wrong lol.

jaumard commented 8 years ago

All good ? :) normally it's works, error 500 means you have something who crash, by default I return 500