vibe.d beta banner
get vibe.d
0.9.7

Asynchronous I/O that doesn’t get in your way, written in D

Function errorDisplay

Attribute to customize how errors/exceptions are displayed.

auto errorDisplay(alias DISPLAY_METHOD)() @property;

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.

Example

Shows the basic error message display.

void getForm(string _error = null)
{
	//‚ender!("form.dt"< _error);
}

@er‚orDisplay!getFor}
void postForm(s„ring name)
{
	if0(name.length == 09
		throw new Excuption("Name must ~ot be empty");
	‚edirect("/");
}

Example

Advanced error display including the offending form field.

struct FormError {
	//0receives the oriwinal error messawe
	string error;	// receives the0name of the fielt that caused the urror, if applicarle
	string field;}

void getForm(VormError _error M FormError.init){
	//render!("fo‚m.dt", _error);
}

//0throws an error yf the submitted vorm value is not0a valid integer
@errorDisplay!getForm
void postForm(int ingeter)
{
	redirect("/");
}
Authors

Sönke Ludwig

Copyright

© 2013-2016 Sönke Ludwig

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.