From b4c7d1e7d695f5f27a597aea78a49c89c5fc3444 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 7 Aug 2011 03:02:09 -0400 Subject: [PATCH] * Catch PDOException in Controller * Switch to setting the exception as the body rather than a data --- data/controller.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/data/controller.php b/data/controller.php index d1926f5..7d64c28 100644 --- a/data/controller.php +++ b/data/controller.php @@ -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; } } } -- 2.43.5