Skip to content

Commit

Permalink
Merge pull request #26 from TSchuermans/feature/rpc-error-data
Browse files Browse the repository at this point in the history
Added JSON-RPC 2.0 error data to response
  • Loading branch information
adlawson committed Jan 7, 2016
2 parents 7e0dc22 + f39fbc1 commit a94d2b2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Message/ResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function getRpcErrorCode();
*/
public function getRpcErrorMessage();

/**
* @return mixed
*/
public function getRpcErrorData();

/**
* @return mixed
*/
Expand Down
8 changes: 8 additions & 0 deletions test/functional/RequestFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
});
}

Expand All @@ -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()
Expand All @@ -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());
});
}

Expand All @@ -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()
Expand All @@ -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());
});
}

Expand All @@ -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()
Expand All @@ -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());
});
}

Expand Down
18 changes: 17 additions & 1 deletion test/unit/Message/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a94d2b2

Please sign in to comment.