From e05e2fdd9d32f85897d264ac3aa65910914987bc Mon Sep 17 00:00:00 2001 From: badaix Date: Tue, 1 Sep 2015 22:52:37 +0200 Subject: [PATCH] added JsonInternalErrorException --- server/jsonrpc.cpp | 51 ---------------------------------------------- server/jsonrpc.h | 18 ++++++++++++++++ 2 files changed, 18 insertions(+), 51 deletions(-) diff --git a/server/jsonrpc.cpp b/server/jsonrpc.cpp index c584e38f..54b6e49a 100644 --- a/server/jsonrpc.cpp +++ b/server/jsonrpc.cpp @@ -130,54 +130,3 @@ Json JsonNotification::getJson(const std::string& method, Json data) return notification; } - - -/* - - if ((method == "get") || (method == "set")) - { - vector params; - try - { - params = request["params"].get>(); - } - catch (const exception& e) - { - throw JsonRpcException(e.what(), -32602); - } - if (method == "get") - { - //{"jsonrpc": "2.0", "method": "get", "params": ["status"], "id": 2} - //{"jsonrpc": "2.0", "method": "get", "params": ["status", "server"], "id": 2} - //{"jsonrpc": "2.0", "method": "get", "params": ["status", "client"], "id": 2} - //{"jsonrpc": "2.0", "method": "get", "params": ["status", "client", "MAC"], "id": 2} - vector params = request["params"].get>(); - for (auto s: params) - logO << s << "\n"; - response["result"] = "???";//nullptr; - } - else if (method == "set") - { - //{"jsonrpc": "2.0", "method": "set", "params": ["volume", "0.9", "client", "MAC"], "id": 2} - //{"jsonrpc": "2.0", "method": "set", "params": ["active", "client", "MAC"], "id": 2} - response["result"] = "234";//nullptr; - } - } - else - throw JsonRpcException("method not found: \"" + method + "\"", -32601); - - connection->send(response.dump()); - -*/ - - - -/* - Json response = { - {"jsonrpc", "2.0"}, - {"id", id} - }; - -*/ - - diff --git a/server/jsonrpc.h b/server/jsonrpc.h index ef4d4e34..4a8546b9 100644 --- a/server/jsonrpc.h +++ b/server/jsonrpc.h @@ -131,6 +131,10 @@ public: }; +// -32601 Method not found The method does not exist / is not available. +// -32602 Invalid params Invalid method parameter(s). +// -32603 Internal error Internal JSON-RPC error. + class JsonMethodNotFoundException : public JsonRequestException { public: @@ -158,4 +162,18 @@ public: }; +class JsonInternalErrorException : public JsonRequestException +{ +public: + JsonInternalErrorException(const JsonRequest& request) : JsonRequestException(request, "internal error", -32603) + { + } + + JsonInternalErrorException(const JsonRequest& request, const std::string& message) : JsonRequestException(request, message, -32603) + { + } +}; + + + #endif