Browse Source

jsonrpc: Report standard JSON-RPC 2.0 error codes.

ppa-0.6.1
ZmnSCPxj 7 years ago
committed by Christian Decker
parent
commit
d03ca59f80
  1. 19
      lightningd/jsonrpc.c

19
lightningd/jsonrpc.c

@ -437,6 +437,8 @@ void json_add_address(struct json_result *response, const char *fieldname,
}
#define JSONRPC2_INVALID_REQUEST -32600
#define JSONRPC2_METHOD_NOT_FOUND -32601
#define JSONRPC2_INVALID_PARAMS -32602
void command_success(struct command *cmd, struct json_result *result)
{
@ -556,25 +558,31 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
tal_add_destructor(jcon->current, destroy_cmd);
if (!method || !params) {
command_fail(jcon->current, method ? "No params" : "No method");
command_fail_detailed(jcon->current,
JSONRPC2_INVALID_REQUEST, NULL,
method ? "No params" : "No method");
return;
}
if (method->type != JSMN_STRING) {
command_fail(jcon->current, "Expected string for method");
command_fail_detailed(jcon->current,
JSONRPC2_INVALID_REQUEST, NULL,
"Expected string for method");
return;
}
cmd = find_cmd(jcon->buffer, method);
if (!cmd) {
command_fail(jcon->current,
command_fail_detailed(jcon->current,
JSONRPC2_METHOD_NOT_FOUND, NULL,
"Unknown command '%.*s'",
(int)(method->end - method->start),
jcon->buffer + method->start);
return;
}
if (cmd->deprecated && !deprecated_apis) {
command_fail(jcon->current,
command_fail_detailed(jcon->current,
JSONRPC2_METHOD_NOT_FOUND, NULL,
"command '%.*s' is deprecated",
(int)(method->end - method->start),
jcon->buffer + method->start);
@ -582,7 +590,8 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
}
if (params->type != JSMN_ARRAY && params->type != JSMN_OBJECT) {
command_fail(jcon->current,
command_fail_detailed(jcon->current,
JSONRPC2_INVALID_PARAMS, NULL,
"Expected array or object for params");
return;
}

Loading…
Cancel
Save