-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added error.data support for JSON-RPC 2.0 (#1)
- Loading branch information
Showing
5 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,30 @@ | |
|
||
namespace Josser\Exception; | ||
|
||
use Josser\Exception\JosserException; | ||
|
||
/** | ||
* RPC fault exception. | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
class RpcFaultException extends \RuntimeException implements JosserException | ||
{ | ||
public function __construct($message, $code = null, $previous = null) | ||
/** | ||
* @var mixed | ||
*/ | ||
private $data; | ||
|
||
public function __construct($message, $code = 0, $data = null, \Exception $previous = null) | ||
{ | ||
$message = 'RPC fault: ' . $message; | ||
$this->data = $data; | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Josser package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Josser\Tests\Exception; | ||
|
||
use Josser\Exception\RpcFaultException; | ||
use Josser\Tests\TestCase as JosserTestCase; | ||
|
||
/** | ||
* Test class for \Josser\Exception\RpcFaultException | ||
*/ | ||
class RpcFaultExceptionTest extends JosserTestCase | ||
{ | ||
public function testException() | ||
{ | ||
$e = new RpcFaultException('message'); | ||
|
||
$this->assertEquals('message', $e->getMessage()); | ||
$this->assertEquals(0, $e->getCode()); | ||
$this->assertEquals(null, $e->getData()); | ||
|
||
$e = new RpcFaultException('message', 100); | ||
|
||
$this->assertEquals('message', $e->getMessage()); | ||
$this->assertEquals(100, $e->getCode()); | ||
$this->assertEquals(null, $e->getData()); | ||
|
||
$e = new RpcFaultException('message', 100, null); | ||
|
||
$this->assertEquals('message', $e->getMessage()); | ||
$this->assertEquals(100, $e->getCode()); | ||
$this->assertEquals(null, $e->getData()); | ||
|
||
$previous = new \Exception; | ||
$e = new RpcFaultException('message', 100, null, $previous); | ||
|
||
$this->assertEquals('message', $e->getMessage()); | ||
$this->assertEquals(100, $e->getCode()); | ||
$this->assertEquals(null, $e->getData()); | ||
$this->assertSame($previous, $e->getPrevious()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters