diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-01-17 16:58:54 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-01-17 16:58:54 -0800 |
commit | 4197ee39b9e9737afbc766d42ec68641d760654a (patch) | |
tree | bc6a37db59af394562d8abd5bfeb75a2e32f03f7 | |
parent | afb3fa71b9aea16a02c13f75d7999069a4ae9d21 (diff) |
Catch ORM_Validation_Exception and turn it into a 400 Bad Request with
appropriate error output.
-rw-r--r-- | modules/rest/controllers/rest.php | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 5ef9eb84..cac49740 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -72,7 +72,14 @@ class Rest_Controller extends Controller { throw new Rest_Exception("Forbidden", 403); } - print call_user_func(array($handler_class, $handler_method), $request); + try { + print call_user_func(array($handler_class, $handler_method), $request); + } catch (ORM_Validation_Exception $e) { + foreach ($e->validation->errors() as $key => $value) { + $msgs[] = "$key: $value"; + } + throw new Rest_Exception("Bad Request: " . join(", ", $msgs), 400); + } } catch (Rest_Exception $e) { rest::send_headers($e); } |