Skip to content

Ability to configure HTTP status code #75

@nonplus

Description

@nonplus

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions