status-go icon indicating copy to clipboard operation
status-go copied to clipboard

Unify RPC response type

Open igor-sirotin opened this issue 1 year ago • 2 comments
trafficstars

Description

We use 3 functions to build an RPC response:

  • makeJSONResponse
  • prepareJSONResponse
  • prepareJSONResponseWithCode

They use 2 different types of responses used.

Because of this we have to parse the response depending on the actual method called.

APIResponse

Definition:

This only allows to return an error: https://github.com/status-im/status-go/blob/91c6949cd25449d5459581a21f2c8b929290ced0/mobile/types.go#L9-L12

I suppose that's why we have some custom response types: https://github.com/status-im/status-go/blob/91c6949cd25449d5459581a21f2c8b929290ced0/mobile/types.go#L14-L25

jsonrpcErrorResponse and jsonrpcSuccessfulResponse

These look more universal. It allows to return an error (with a code defined) or data.

Definition:

https://github.com/status-im/status-go/blob/c0c963bdaade096dd0ce6eb7b9eed9ef7620f652/mobile/response.go#L28-L39

Problem

The main interesting field in these responses is error. And it's defined at different levels (response.Error vs response.Error.Message), so I have to know what to expect from particular endpoint.

igor-sirotin avatar Mar 15 '24 12:03 igor-sirotin

cc @cammellos

igor-sirotin avatar Mar 15 '24 12:03 igor-sirotin

@igor-sirotin @cammellos Hi, I would really like to work on this issue (: I see that it hasn't been taken up yet, so is it okay if I start working on this one?

AryanGodara avatar Mar 25 '24 19:03 AryanGodara