diff --git a/server/libs/Controller.php b/server/libs/Controller.php index a3472bfa..f634c1ba 100755 --- a/server/libs/Controller.php +++ b/server/libs/Controller.php @@ -19,7 +19,7 @@ abstract class Controller { $this->validate(); $this->handler(); } catch (\Exception $exception) { - Response::respondError($exception->getMessage()); + Response::respondError($exception->getMessage(), $exception); return; } }; diff --git a/server/libs/RequestException.php b/server/libs/RequestException.php index 540eae80..b454478e 100644 --- a/server/libs/RequestException.php +++ b/server/libs/RequestException.php @@ -1,2 +1,2 @@ - 'fail', 'message' => $errorMsg, - 'data' => $data + 'data' => null ); + self::$responseException = $exception; $app = \Slim\Slim::getInstance(); $app->response->headers->set('Content-Type', 'application/json'); - $app->response->setBody(json_encode($response)); + $app->response->setBody(json_encode(self::$response)); $app->response->finalize(); } public static function respondSuccess($data = null) { - $response = array( + self::$response = array( 'status' => 'success', 'data' => $data ); $app = \Slim\Slim::getInstance(); $app->response->headers->set('Content-Type', 'application/json'); - $app->response->setBody(json_encode($response)); + $app->response->setBody(json_encode(self::$response)); $app->response->finalize(); } diff --git a/server/tests/models/ResponseTest.php b/server/tests/models/ResponseTest.php index 89888e78..2ff1c31b 100755 --- a/server/tests/models/ResponseTest.php +++ b/server/tests/models/ResponseTest.php @@ -8,17 +8,17 @@ class ResponseTest extends TestCase { public function testErrorResponseFormat() { //Mock data $mockErrorValue = 'MOCK_ERROR_VALUE'; - $mockData = array('example' => true); + $mockException = array('example' => true); $expectedArgument = json_encode(array( 'status' => 'fail', 'message' => $mockErrorValue, - 'data' => $mockData + 'data' => null )); $responseInstance = \Slim\Slim::getInstance(); $responseInstance = $responseInstance->response; //Execute Response - Response::respondError($mockErrorValue, $mockData); + Response::respondError($mockErrorValue, $mockException); //Should have been called with expected format $this->assertTrue($responseInstance->setBody->hasBeenCalledWithArgs($expectedArgument));