mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
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:
parent
d2b4ee0380
commit
85da187f85
@ -314,6 +314,15 @@ class LeftAndMain extends Controller {
|
|||||||
SSViewer::set_theme(null);
|
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
|
* If this is set to true, the "switchView" context in the
|
||||||
|
Loading…
Reference in New Issue
Block a user