How to make Document validator to return 400 error code instead of 500 error code

  • I have added some custom attributes in Nuxeo with Length constraint.
  • Given the below the sample schema file
    <xs:element name="latitude">
    <xs:simpleType>
        <xs:restriction base="xs:double">
            <xs:minInclusive value="-90.0"/>
            <xs:maxInclusive value="90.0"/>
        </xs:restriction>
    </xs:simpleType>
    </xs:element>
    
  • While creating a document with custom property If the constraint is violated then Nuxeo returns the 500 error code.
  • Is there any way to change error code from 500 to 400.
  • I tried to change the messages.properties file but the only Error message was updated.
0 votes

1 answers

150 views

ANSWER



  • Accept header is required in the request. If the Accept is missing Nuxeo validator throws 500 error.

    {
    "entity-type": "exception",
    "status": 500,
    "message": "2 constraint violation(s) thrown. First one is: 'Value is required.', call DocumentValidationException.getViolations() to get the others"
    }
    
  • If Accept header is present then validator returns following response

    {
    "entity-type": "validation_report",
    "has_error": true,
    "number": 2,
    "violations": [
        {
            "message": "Value is required.",
            "invalid_value": null,
            "constraint": {
                "entity-type": "validation_constraint",
                "name": "NotNullConstraint",
                "parameters": {}
            },
            "path": [
                {
                    "field_name": "sample_key1",
                    "is_list_item": false
                }
            ]
        },
        {
            "message": "Value is required.",
            "invalid_value": null,
            "constraint": {
                "entity-type": "validation_constraint",
                "name": "NotNullConstraint",
                "parameters": {}
            },
            "path": [
                {
                    "field_name": "sample_key2",
                    "is_list_item": false
                }
            ]
        }
    ]
    }
    
0 votes