Skip to content

Conversation

@goce-h4
Copy link
Contributor

@goce-h4 goce-h4 commented Mar 23, 2020

This PR examines the approaches for throwing an error in the rpc methods .

  1. The RPC methods will throw CodedRpcException.
  2. The exception will be intercepted in the json rpc handler and it will be return as resolved promise with the error code and error object with message.

However the unit tests will need to test for errors like this:

return request(server.server)
      .post("/rpc/v1")
      .send({ method: "test.testError", params: { data: "hi" } })
      .expect(403)
      .expect(errorObj);

instead of testing the promise to fail like this:
expect(req).rejects.toEqual

We still need to see if and how we will use global exception handlers and how we will audit the errors which needs to be audited.

p.s Some of the console logs are left on purpose for testing.

goce-h4 added 3 commits March 23, 2020 16:26
- parse the error object in the json-rpc handler
- added test rpc method which throws an error
@goce-h4 goce-h4 requested review from a user, rm-h4 and spion March 23, 2020 15:40
Copy link

@rm-h4 rm-h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should expect more error codes in future

@UseInterceptors(TestInterceptor)
@UseGuards(TestGuard)
public async testError(params: any) {
console.log("Throw an error !!!");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls delete console logs

src/index.ts Outdated
error => ({ error })
);

console.log(response);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete console logs

@spion-h4 spion-h4 merged commit e79b547 into master Mar 24, 2020
@spion-h4 spion-h4 deleted the goce/H4C-246_error_handling_rpc_module branch March 24, 2020 15:24
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.

4 participants