Skip to content

Incorrect error message when an nlohmann type_error is thrown in rpc method #48

Open
@samkottler

Description

@samkottler

If there is an unhandled type_error thrown in the rpc method itself, the error should be an internal error not an invalid parameters error. For example, this program

#include "nlohmann/json.hpp"
#include "jsonrpccxx/server.hpp"
#include <iostream>

std::string do_something()
{
  nlohmann::json json = 0;
  std::string my_string = json;
  return my_string;
}

int main()
{
  jsonrpccxx::JsonRpc2Server handler;
  handler.Add("do_something", jsonrpccxx::GetHandle(&do_something), {});

  std::string request = R"({"jsonrpc": "2.0", "id": 0, "method": "do_something", "params": []})";

  std::cout << handler.HandleRequest(request) << std::endl;
}

prints

{"error":{"code":-32602,"message":"invalid parameter: [json.exception.type_error.302] type must be string, but is number"},"id":0,"jsonrpc":"2.0"}

which doesn't make sense because the exception is thrown in the body of do_something, not when converting parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions