Skip to content

Basic error handling

zhaber edited this page Aug 2, 2012 · 2 revisions

The framework contains an error handling mechanism that catches validation exceptions on the server side and coordinates their transfer to the client, where each error is subsequently processed by the client library. Validation error messages are defined on a subrule level which allows a more specific and thus more helpful description of failure:

parameterName converter1 [errorId1] >> validationRule1 [errorId2] >> validationRule2 [errorId2] >> ...

You can use any Groovy object as an error id, for example:

nights trim >> isEven [Number of nights cannot be odd]

To localize a message, you can use fields of the object m and the rule engine will read the property with the corresponding name from a resource bundle specified in a configuration file, for example:

nights isEven [m.notEven] // notEven property from a resource bundle

If no error message was defined for some subrule, then it is taken from the nearest subsequent subrule with a message, and if there is no such subrule, an empty string is used instead. In this way the error message can cover multiple subrules simultaneously.