Catch ORM_Validation_Exception and turn it into a 400 Bad Request with

appropriate error output.
This commit is contained in:
Bharat Mediratta
2010-01-17 16:58:54 -08:00
parent afb3fa71b9
commit 4197ee39b9

View File

@@ -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);
}