* Catch PDOException in Controller
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 7 Aug 2011 07:02:09 +0000 (03:02 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 7 Aug 2011 07:02:09 +0000 (03:02 -0400)
* Switch to setting the exception as the body rather than a data

data/controller.php

index d1926f50f0616d78ced1a297553f9a9a55cb1b6a..7d64c283fcd42346af0d5276e26e49db9f97e2ea 100644 (file)
@@ -48,8 +48,11 @@ class Controller extends http\RestAction
     try {
       $response->data = $this->model->Fetch();
     } catch (ModelException $e) {
-      $response->data['message'] = $e->GetMessage();
+      $response->body = $e->GetMessage();
       $response->response_code = http\ResponseCode::NOT_FOUND;
+    } catch (\PDOException $e) {
+      $response->body = $e->GetMessage();
+      $response->response_code = http\ResponseCode::INTERNAL_SERVER_ERROR;
     }
   }
 
@@ -61,8 +64,11 @@ class Controller extends http\RestAction
       $this->model->Update();
       $response->data = $this->model->Fetch();
     } catch (ModelException $e) {
-      $response->data['message'] = $e->GetMessage();
+      $response->body = $e->GetMessage();
       $response->response_code = http\ResponseCode::NOT_FOUND;
+    } catch (\PDOException $e) {
+      $response->body = $e->GetMessage();
+      $response->response_code = http\ResponseCode::INTERNAL_SERVER_ERROR;
     }
   }
 
@@ -73,8 +79,11 @@ class Controller extends http\RestAction
     try {
       $this->model->Delete();
     } catch (ModelException $e) {
-      $response->data['message'] = $e->GetMessage();
+      $response->body = $e->GetMessage();
       $response->response_code = http\ResponseCode::BAD_REQUEST;
+    } catch (\PDOException $e) {
+      $response->body = $e->GetMessage();
+      $response->response_code = http\ResponseCode::INTERNAL_SERVER_ERROR;
     }
   }
 
@@ -86,8 +95,11 @@ class Controller extends http\RestAction
       $this->model->Insert();
       $response->data = $this->model->Fetch();
     } catch (ModelException $e) {
-      $response->data['message'] = $e->GetMessage();
+      $response->body = $e->GetMessage();
       $response->response_code = http\ResponseCode::BAD_REQUEST;
+    } catch (\PDOException $e) {
+      $response->body = $e->GetMessage();
+      $response->response_code = http\ResponseCode::INTERNAL_SERVER_ERROR;
     }
   }
 }