1 | /************************************************************************* |
---|---|
2 | * libjson-rpc-cpp |
3 | ************************************************************************* |
4 | * @file errors.cpp |
5 | * @date 31.12.2012 |
6 | * @author Peter Spiess-Knafl <dev@spiessknafl.at> |
7 | * @license See attached LICENSE.txt |
8 | ************************************************************************/ |
9 | |
10 | #include "errors.h" |
11 | #include "exception.h" |
12 | |
13 | using namespace jsonrpc; |
14 | |
15 | std::map<int, std::string> Errors::possibleErrors; |
16 | Errors::_init Errors::_initializer; |
17 | |
18 | const int Errors::ERROR_RPC_JSON_PARSE_ERROR = -32700; |
19 | const int Errors::ERROR_RPC_METHOD_NOT_FOUND = -32601; |
20 | const int Errors::ERROR_RPC_INVALID_REQUEST = -32600; |
21 | const int Errors::ERROR_RPC_INVALID_PARAMS = -32602; |
22 | const int Errors::ERROR_RPC_INTERNAL_ERROR = -32603; |
23 | |
24 | const int Errors::ERROR_SERVER_PROCEDURE_IS_METHOD = -32604; |
25 | const int Errors::ERROR_SERVER_PROCEDURE_IS_NOTIFICATION = -32605; |
26 | const int Errors::ERROR_SERVER_PROCEDURE_POINTER_IS_NULL = -32606; |
27 | const int Errors::ERROR_SERVER_PROCEDURE_SPECIFICATION_NOT_FOUND = -32000; |
28 | const int Errors::ERROR_SERVER_CONNECTOR = -32002; |
29 | const int Errors::ERROR_SERVER_PROCEDURE_SPECIFICATION_SYNTAX = -32007; |
30 | |
31 | const int Errors::ERROR_CLIENT_CONNECTOR = -32003; |
32 | const int Errors::ERROR_CLIENT_INVALID_RESPONSE = -32001; |
33 | |
34 | Errors::_init::_init() { |
35 | // Official Errors |
36 | possibleErrors[ERROR_RPC_INVALID_REQUEST] = "INVALID_JSON_REQUEST: The JSON " |
37 | "sent is not a valid JSON-RPC " |
38 | "Request object"; |
39 | possibleErrors[ERROR_RPC_METHOD_NOT_FOUND] = "METHOD_NOT_FOUND: The method " |
40 | "being requested is not " |
41 | "available on this server"; |
42 | possibleErrors[ERROR_RPC_INVALID_PARAMS] = "INVALID_PARAMS: Invalid method " |
43 | "parameters (invalid name and/or " |
44 | "type) recognised"; |
45 | possibleErrors[ERROR_RPC_JSON_PARSE_ERROR] = "JSON_PARSE_ERROR: The JSON-Object is not JSON-Valid"; |
46 | possibleErrors[ERROR_RPC_INTERNAL_ERROR] = "INTERNAL_ERROR: "; |
47 | |
48 | possibleErrors[ERROR_SERVER_PROCEDURE_IS_METHOD] = "PROCEDURE_IS_METHOD: The requested notification is declared as a method"; |
49 | possibleErrors[ERROR_SERVER_PROCEDURE_IS_NOTIFICATION] = "PROCEDURE_IS_NOTIFICATION: The requested method is declared as " |
50 | "notification"; |
51 | possibleErrors[ERROR_SERVER_PROCEDURE_POINTER_IS_NULL] = "PROCEDURE_POINTER_IS_NULL: Server has no function Reference registered"; |
52 | possibleErrors[ERROR_SERVER_PROCEDURE_SPECIFICATION_NOT_FOUND] = "Configuration file was not found"; |
53 | |
54 | possibleErrors[ERROR_SERVER_PROCEDURE_SPECIFICATION_SYNTAX] = "Procedure specification mallformed"; |
55 | |
56 | possibleErrors[ERROR_CLIENT_INVALID_RESPONSE] = "The response is invalid"; |
57 | possibleErrors[ERROR_CLIENT_CONNECTOR] = "Client connector error"; |
58 | possibleErrors[ERROR_SERVER_CONNECTOR] = "Server connector error"; |
59 | } |
60 | |
61 | std::string Errors::GetErrorMessage(int errorCode) { |
62 | if (possibleErrors.find(errorCode) == possibleErrors.end()) { |
63 | return ""; |
64 | } |
65 | return possibleErrors[errorCode]; |
66 | } |
67 |