From 38f034aa34c9c39a45c7714585c9ab16c21c0b98 Mon Sep 17 00:00:00 2001 From: dongwei <838456736@qq.com> Date: Wed, 30 Jan 2019 14:48:41 +0800 Subject: [PATCH] include influxdb --- src/Middleware/TunnelMiddleware.php | 2 +- src/Server/JsonRpcMethod.php | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Middleware/TunnelMiddleware.php b/src/Middleware/TunnelMiddleware.php index 3d49b7f..84370fd 100644 --- a/src/Middleware/TunnelMiddleware.php +++ b/src/Middleware/TunnelMiddleware.php @@ -42,7 +42,7 @@ class TunnelMiddleware $content = $response->getOriginalContent(); $status = isset($content['error']) ? $content['error']['code'] : 200; - $client = new \InfluxDB\Client('http://localhost', '8086'); + $client = new \InfluxDB\Client('127.0.0.1', '8086'); $database = $client->selectDB('rpc_monitor'); $points = array( new Point( diff --git a/src/Server/JsonRpcMethod.php b/src/Server/JsonRpcMethod.php index a5ca9ef..e91531a 100644 --- a/src/Server/JsonRpcMethod.php +++ b/src/Server/JsonRpcMethod.php @@ -28,14 +28,24 @@ class JsonRpcMethod extends JsonRpcBase public function error($code, $msg) { - return [ - 'jsonrpc' => '2.0', - 'error' => [ - 'code' => $code, - 'message' => is_array($msg) ? json_encode($msg) : $msg, - ], - 'id' => $this->id - ]; + return is_string($msg) + ? [ + 'jsonrpc' => '2.0', + 'error' => [ + 'code' => $code, + 'message' => $msg, + ], + 'id' => $this->id + ] + : [ + 'jsonrpc' => '2.0', + 'error' => [ + 'code' => $code, + 'message' => self::ErrorMsg[$code], + 'data' => $msg + ], + 'id' => $this->id + ]; } } \ No newline at end of file