Skip to content

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Apr 17, 2023

This allows passing an Error class object to one of the predefined error functions as defined in rpcErrors and providerErrors. Upon calling the serialise function of the JsonRpcError class, the cause error will be serialised using the serializeCause function.

For example:

const error = rpcErrors.invalidParams({
  data: {
    cause: new Error('foo bar'),
  },
});

Callng error.serialize() results in:

{
  "code": -32602,
  "message": "Invalid method parameter(s).",
  "data": {
    "cause": {
      "stack": "Error: foo bar [...]",
      "message": "foo bar"
    }
  },
  "stack": "Error: Invalid method parameter(s). [...]"
}

Mrtenz added 2 commits April 17, 2023 15:50
This allows passing an `Error` class object to one of the predefined error functions as defined in `rpcErrors` and `providerErrors`. Upon calling the `serialise` function of the `JsonRpcError` class, the cause error will be serialised using the `serializeCause` function.
The expect function ensures that the type of error.serialize().data is an object and contains specific serialized data while ensuring it does not contain an error instance. This test is necessary to avoid unexpected errors during exception handling.
@Mrtenz Mrtenz requested a review from a team as a code owner April 17, 2023 14:04
@Mrtenz Mrtenz merged commit e6a9162 into main Apr 17, 2023
@Mrtenz Mrtenz deleted the mrtenz/error-cause branch April 17, 2023 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants