diff --git a/src/Message/Response.php b/src/Message/Response.php index 74b8e58..867b932 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -39,6 +39,16 @@ public function getRpcErrorMessage() return isset($error['message']) ? $error['message'] : null; } + /** + * {@inheritdoc} + */ + public function getRpcErrorData() + { + $error = $this->getFieldFromBody('error'); + + return isset($error['data']) ? $error['data'] : null; + } + /** * {@inheritdoc} */ diff --git a/src/Message/ResponseInterface.php b/src/Message/ResponseInterface.php index f902a4e..80dc065 100644 --- a/src/Message/ResponseInterface.php +++ b/src/Message/ResponseInterface.php @@ -28,6 +28,11 @@ public function getRpcErrorCode(); */ public function getRpcErrorMessage(); + /** + * @return mixed + */ + public function getRpcErrorData(); + /** * @return mixed */ diff --git a/test/functional/RequestFunctionalTest.php b/test/functional/RequestFunctionalTest.php index 019e623..71417a0 100644 --- a/test/functional/RequestFunctionalTest.php +++ b/test/functional/RequestFunctionalTest.php @@ -48,6 +48,7 @@ public function testConcatRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertEquals(null, $response->getRpcErrorCode()); $this->assertEquals(null, $response->getRpcErrorMessage()); + $this->assertEquals(null, $response->getRpcErrorData()); } public function testConcatAsyncRequest() @@ -69,6 +70,7 @@ public function testConcatAsyncRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertEquals(null, $response->getRpcErrorCode()); $this->assertEquals(null, $response->getRpcErrorMessage()); + $this->assertEquals(null, $response->getRpcErrorData()); }); } @@ -90,6 +92,7 @@ public function testSumRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertEquals(null, $response->getRpcErrorCode()); $this->assertEquals(null, $response->getRpcErrorMessage()); + $this->assertEquals(null, $response->getRpcErrorData()); } public function testSumAsyncRequest() @@ -111,6 +114,7 @@ public function testSumAsyncRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertEquals(null, $response->getRpcErrorCode()); $this->assertEquals(null, $response->getRpcErrorMessage()); + $this->assertEquals(null, $response->getRpcErrorData()); }); } @@ -131,6 +135,7 @@ public function testFooRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertEquals(null, $response->getRpcErrorCode()); $this->assertEquals(null, $response->getRpcErrorMessage()); + $this->assertEquals(null, $response->getRpcErrorData()); } public function testFooAsyncRequest() @@ -151,6 +156,7 @@ public function testFooAsyncRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertEquals(null, $response->getRpcErrorCode()); $this->assertEquals(null, $response->getRpcErrorMessage()); + $this->assertEquals(null, $response->getRpcErrorData()); }); } @@ -171,6 +177,7 @@ public function testBarRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertTrue(is_int($response->getRpcErrorCode())); $this->assertTrue(is_string($response->getRpcErrorMessage())); + $this->assertEquals(null, $response->getRpcErrorData()); } public function testBarAsyncRequest() @@ -191,6 +198,7 @@ public function testBarAsyncRequest() $this->assertEquals($id, $response->getRpcId()); $this->assertTrue(is_int($response->getRpcErrorCode())); $this->assertTrue(is_string($response->getRpcErrorMessage())); + $this->assertEquals(null, $response->getRpcErrorData()); }); } diff --git a/test/unit/Message/ResponseTest.php b/test/unit/Message/ResponseTest.php index 0a32193..3cdccf8 100644 --- a/test/unit/Message/ResponseTest.php +++ b/test/unit/Message/ResponseTest.php @@ -73,7 +73,23 @@ public function testGetRpcErrorMessageIsNull() { $response = new Response(200); - $this->assertNull($response->getRpcErrorCode()); + $this->assertNull($response->getRpcErrorMessage()); + } + + public function testGetRpcErrorData() + { + $response = new Response(200, [], json_encode([ + 'error' => ['data' => array()] + ])); + + $this->assertEquals(array(), $response->getRpcErrorData()); + } + + public function testGetRpcErrorDataIsNull() + { + $response = new Response(200); + + $this->assertNull($response->getRpcErrorData()); } public function testGetRpcResult()