From 4197ee39b9e9737afbc766d42ec68641d760654a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 17 Jan 2010 16:58:54 -0800 Subject: Catch ORM_Validation_Exception and turn it into a 400 Bad Request with appropriate error output. --- modules/rest/controllers/rest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'modules/rest/controllers/rest.php') 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); } -- cgit v1.2.3