/**
  * Test static method with error messages
  */
 public function testFromError()
 {
     $expected = new \Exception(__METHOD__, JsonRpcException::CODE_UNKNOWN_ERROR);
     $data = ['type' => E_ERROR, 'code' => $expected->getCode(), 'message' => $expected->getMessage(), 'file' => $expected->getFile(), 'line' => $expected->getLine()];
     $actual = call_user_func_array(['JsonRpc\\Base\\JsonRpcException', 'fromError'], $data);
     $this->assertEquals(JsonRpcException::CODE_INTERNAL_ERROR, $actual->getCode());
     $this->assertEquals(JsonRpcException::getErrorMessage($actual->getCode()), $actual->getMessage());
     $this->assertEquals($data, $actual->getData());
     $this->assertNull($actual->getPrevious());
 }
Example #2
0
 /**
  * @param \JsonRpc\Base\JsonRpcException $exception
  */
 protected function respondError(JsonRpcException $exception)
 {
     $response = ['jsonrpc' => self::JSONRPC_VERSION, 'error' => ['code' => $exception->getCode(), 'message' => $exception->getMessage()], 'id' => $this->_id];
     $data = $exception->getData();
     if ($data !== null) {
         $response['error']['data'] = $data;
     }
     if (ob_get_level()) {
         ob_end_clean();
     }
     $this->_transport->respond($response, $exception->getCode(), $this->headers);
 }
Example #3
0
 protected static function getErrorMessages()
 {
     $messages = parent::getErrorMessages();
     $messages[self::CODE_INVALID_RESPONSE] = 'Invalid Response.';
     return $messages;
 }