Skip to content

test: Avoid empty errmsg in JSONRPCException #276

@kevkevinpal

Description

@kevkevinpal

mentioned in: bitcoin#34575

"> * I think JSON-RPC 2 is meant to always use HTTP status 200 regardless of error but cannot find it in the specification, I guess adding it is okay, it's being sent in everywhere after all.

See https://github.com/bitcoin/bitcoin/blob/35e6444fdc4068adc79082648f9889ad593e623b/doc/JSON-RPC-interface.md#json-rpc-11-vs-20

  • The old output on master

    Method not found (-32601)

    was nicer than the PR's

    {'code': -32601, 'message': 'Method not found'} [http_status=200]

Yeah, happy to review a follow-up improving the wording. One could use something like (untested):

 class JSONRPCException(Exception):
    def __init__(self, rpc_error, http_status=None):
        message = rpc_error.pop("message", "INTERNAL ERROR: message field missing in rpc error dict")
        code = rpc_error.pop("code", "INTERNAL_ERROR: code field missing in rpc error dict")
        extra = f'{rpc_error}' if rpc_error else ''
        super().__init__(f"{message} ({code}) {extra} [http_status={http_status}]")
" - maflcko

Metadata

Metadata

Assignees

No one assigned

    Labels

    followupThis is a possible follow-up someone can work onneed to confirmNeed to confirm if this is still needed or already done

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions