fix(libstatus): add safety check before accessing API response

We've introduced a regression in https://github.com/status-im/status-desktop/commit/f1e83f74b#diff-f35edd413addd14c1f81816d6b5ee2bcbdf85fa0e3295d324cb78c98e26d4327L364 where we check whether an RPC's `error` is `null`
and its `result` is not `null`.

This breaks the application with an illegal storage access,
 as in case of a successful API call, the response will have only a `result` key
 (even when it's `null`).

Since we haven't done anything with a possible `error` in the reponse even before
that change was made, this commit removes the `error` check and safe guards around
whether `result` exists.

Fixes #2062
This commit is contained in:
Pascal Precht 2021-03-17 11:10:33 +01:00 committed by Pascal Precht
parent 362ad02ffc
commit 9faf349b83
1 changed files with 1 additions and 1 deletions

View File

@ -376,7 +376,7 @@ proc myPendingRequestsToJoin*(): seq[CommunityMembershipRequest] =
let rpcResult = callPrivateRPC("myPendingRequestsToJoin".prefix).parseJSON()
var communityRequests: seq[CommunityMembershipRequest] = @[]
if rpcResult{"error"}.kind == JNull and rpcResult{"result"}.kind != JNull:
if rpcResult.hasKey("result") and rpcResult{"result"}.kind != JNull:
for jsonCommunityReqest in rpcResult["result"]:
communityRequests.add(jsonCommunityReqest.toCommunityMembershipRequest())