From 41ca2b0195bf6a29429dfc5405f3c2073b1c3aba Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 Jun 2010 13:52:48 -0700 Subject: Rework our exception framework to fit into Kohana's model better. Instead of overwriting Kohana_Exception::handle() (which we were doing in MY_Kohana_Exception) we instead use their existing template system. gallery/views/kohana/error.php overrides system/views/kohana/error.php and is the standard error template for all exceptions. Our version of error.php figures out the appropriate view based on context (cli, authenticated admin, guest viewing a 404, guest viewing a system error) and delegates appropriately. Each delegated view has a narrow responsibility. This paves the way for us to add new error views per module. For example, the rest module will define its own template in Rest_Exception and then its exceptions can be rendered the way that it wants (json encoded, in that case). --- modules/gallery/helpers/item_rest.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 0839b144..6869181d 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -161,20 +161,22 @@ class item_rest_Core { case "photo": case "movie": if (empty($request->file)) { - throw new Rest_Exception("file: Upload failed", 400); + throw new Rest_Exception( + "Bad Request", 400, array("errors" => array("file" => t("Upload failed")))); } - $item->type = $entity->type; - $item->parent_id = $parent->id; - $item->set_data_file($request->file); - $item->name = $entity->name; - $item->title = isset($entity->title) ? $entity->title : $entity->name; - $item->description = isset($entity->description) ? $entity->description : null; - $item->slug = isset($entity->slug) ? $entity->slug : null; - $item->save(); - break; + $item->type = $entity->type; + $item->parent_id = $parent->id; + $item->set_data_file($request->file); + $item->name = $entity->name; + $item->title = isset($entity->title) ? $entity->title : $entity->name; + $item->description = isset($entity->description) ? $entity->description : null; + $item->slug = isset($entity->slug) ? $entity->slug : null; + $item->save(); + break; default: - throw new Rest_Exception("Invalid type: $entity->type", 400); + throw new Rest_Exception( + "Bad Request", 400, array("errors" => array("type" => "invalid"))); } return array("url" => rest::url("item", $item)); -- cgit v1.2.3