Shows the basic error message display.
void getForm(string _error = null) { //render!("form.dt", _error); } @errorDisplay!getForm void postForm(string name) { if (name.length == 0) throw new Exception("Name must not be empty"); redirect("/"); }
Advanced error display including the offending form field.
struct FormError { // receives the original error message string error; // receives the name of the field that caused the error, if applicable string field; } void getForm(FormError _error = FormError.init) { //render!("form.dt", _error); } // throws an error if the submitted form value is not a valid integer @errorDisplay!getForm void postForm(int ingeter) { redirect("/"); }
Attribute to customize how errors/exceptions are displayed.
The first template parameter takes a function that maps an exception and an optional field name to a single error type. The result of this function will then be passed as the _error parameter to the method referenced by the second template parameter.
Supported types for the _error parameter are bool, string, Exception, or a user defined struct. The field member, if present, will be set to null if the exception was thrown after the field validation has finished.