Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to configure HTTP status code #75

Open
nonplus opened this issue Jan 20, 2018 · 0 comments
Open

Ability to configure HTTP status code #75

nonplus opened this issue Jan 20, 2018 · 0 comments

Comments

@nonplus
Copy link
Contributor

nonplus commented Jan 20, 2018

When validation fails, the library used to return a 400 (Bad Request) response. Then this was changed to 409 (Conflict) for some unexplained reason. 9ad8c87#diff-b83d27d3c5374e6d6de83271284db8c4

There doesn't seem to be 100% agreement on what an appropriate REST validation status code should be, but the most commonly used values are 400 or 422. A 409 response only makes sense in a subset of cases (i.e. parameters are structurally valid but there is a business logic conflict).

I believe I can add a custom error handler via configuration options, but it would be nice if I could simply configure the default response code for failed validation, i.e.:

server.use(restifyValidation.validationPlugin({
    failedValidationResponseCode: 400
}));

I'd be happy to provide a PR for this (let me know what the "failedValidationResponseCode" configuration property should be called).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant