API Handle uncaught ValidationException on CMS controller execution

This removes the need for a lot of boilerplate code
around DataObject->write() logic, and avoids generic 500 errors
on user-level failures. This should really be a per-project choice,
but at the moment request handling doesn't allow to configure
custom exception handling.
This commit is contained in:
Ingo Schommer 2013-03-08 12:35:27 +01:00
parent d2b4ee0380
commit 85da187f85

View File

@ -314,6 +314,15 @@ class LeftAndMain extends Controller {
SSViewer::set_theme(null);
}
public function handleRequest(SS_HTTPRequest $request) {
try {
return parent::handleRequest($request);
} catch(ValidationException $e) {
// Nicer presentation of model-level validation errors
return $this->httpError(403, $e->getResult()->message());
}
}
/**
* If this is set to true, the "switchView" context in the