diff --git a/src/Server/JsonRpcBase.php b/src/Server/JsonRpcBase.php new file mode 100644 index 0000000..4291e81 --- /dev/null +++ b/src/Server/JsonRpcBase.php @@ -0,0 +1,29 @@ + 'Method not found', + self::Rpc_Error_Parse_Error => 'Json parse error', + self::Rpc_Error_Invalid_Request => 'Invalid request', + self::Rpc_Error_Invalid_Params => 'Invalid params', + self::Rpc_Error_Internal_Error => 'Internal error', + self::Rpc_Error_System_Error => 'System error', + self::Rpc_Success => 'Success' + ]; +} \ No newline at end of file diff --git a/src/Server/JsonRpcMethod.php b/src/Server/JsonRpcMethod.php index 555e5c6..4f280bc 100644 --- a/src/Server/JsonRpcMethod.php +++ b/src/Server/JsonRpcMethod.php @@ -3,8 +3,9 @@ namespace JsonRpc\Server; use Illuminate\Http\JsonResponse; +use JsonRpc\Exception\RpcServerException; -class JsonRpcMethod +class JsonRpcMethod extends JsonRpcBase { protected $id; protected $request; @@ -24,8 +25,14 @@ class JsonRpcMethod ]; } + /** + * @param $code + * @param $msg + * @return array + */ public function error($code, $msg) { + return [ 'jsonrpc' => '2.0', 'error' => [ diff --git a/src/Server/JsonRpcServer.php b/src/Server/JsonRpcServer.php index 1131403..3f48327 100644 --- a/src/Server/JsonRpcServer.php +++ b/src/Server/JsonRpcServer.php @@ -6,24 +6,8 @@ namespace JsonRpc\Server; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -class JsonRpcServer +class JsonRpcServer extends JsonRpcBase { - const Rpc_Error_Parse_Error = -32700; - const Rpc_Error_Invalid_Request = -32600; - const Rpc_Error_NOT_FOUND = -32601; - const Rpc_Error_Invalid_Params = -32602; - const Rpc_Error_Internal_Error = -32603; - const Rpc_Success = 0; - - - const ErrorMsg = [ - self::Rpc_Error_NOT_FOUND => 'Method not found', - self::Rpc_Error_Parse_Error => 'Json parse error', - self::Rpc_Error_Invalid_Request => 'Invalid request', - self::Rpc_Error_Invalid_Params => 'Invalid params', - self::Rpc_Success => 'Success' - ]; - /** * @var Request */