nervosnetwork / fiber

21 stars 11 forks source link

[rpc] rpc returns the same error code when an error occurs #320

Open ahonn opened 3 days ago

ahonn commented 3 days ago

When an error occurs while calling different RPC methods, the returned error code is always the same (-32000).

As a result, one must rely on the error message, which is not the best practice. To simplify the handling of related errors, it is recommended that RPC error codes be standardized.

For example, when sending payment to an expired invoice, the following error will be returned:

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "InvalidParameter: Failed to validate payment request: \"invoice is expired\"",
    "data": {
      "target_pubkey": null,
      "amount": null,
      "payment_hash": null,
      "final_cltv_delta": null,
      "invoice": "fibt10000000001pfw653wmq4nczxzat8almjaujsncds6z3y5989ey5qaj4fm3h6k543smrppgg8rh895jp0g7ndzja6adhc4perqttv4nuqm9rqqal78pcceghel2ce057fm3prdzuklgezp6m4aej4dxy7vhfpf5dup3uz74t52f4nscaw8dlq4vt75e3vd37y3957x5583darjurl9sw8puz5spm4mmcglamtdtpcc997yzm65t2lqsajgkdsfcurgq7zjwdqcdj5q7ydgwn52m7y9gm7zn593fh976r8dw593hasyrwkz9qwz8nnqwk7fgpxkrhmdxgphvjhr5qmqsnaul5mkvxcggtx5s72c8p4h0p996ul27u49smfdqrpqeugvnqecrhczrcj8437hwfunfwjj6rvds6ykszrhv6ez8wykztsy8s6jvdu555z7mu6q7cdvzwnftlnh4f6wljpncjrg58mek3jpq9lytsusd4gv3s3yyqzymyvza20yssevrsdw6rgxx299xvfppgw7mptmg2vf8qlf7hq54gqqmczmma",
      "timeout": null,
      "max_fee_amount": null,
      "max_parts": null,
      "keysend": null,
      "udt_type_script": null,
      "allow_self_payment": true
    }
  },
  "id": 42
}

I can only determine whether the error is due to the expired invoice by checking if the error message contains "invoice is expired."

chenyukang commented 3 days ago

yeah, we need to improve this.