Skip to content

Commit

Permalink
fix(rpc/client): fixes parsing of responses with falsy result values
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Nov 4, 2019
1 parent d499b66 commit 3f49070
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/rpc/src/client/ClientManager/ClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
RPCCompleteNotification,
RPCNotification,
RPCSingleResponse,
DataParser
DataParser,
RPCErrorResponse
} from '~/types';
import { ConnectionManager } from './ConnectionManager';
import { ClientStore } from './ClientStore';
Expand Down Expand Up @@ -179,7 +180,7 @@ export class ClientManager {
if (
notification.method === ':complete' &&
notification.params &&
notification.params.id
Object.hasOwnProperty.call(notification.params, 'id')
) {
return this.complete(notification.params.id, false);
}
Expand All @@ -191,14 +192,19 @@ export class ClientManager {
// Response
const response: RPCSingleResponse = data;

if (response.error) {
const error = mapError(response);
return response.id
if (Object.hasOwnProperty.call(response, 'error')) {
const error = mapError(response as RPCErrorResponse);
return Object.hasOwnProperty.call(response, 'id') &&
response.id !== null
? this.error(response.id, error, false)
: this.report(error);
}

if (response.result && response.id) {
if (
Object.hasOwnProperty.call(response, 'result') &&
Object.hasOwnProperty.call(response, 'id') &&
response.id !== null
) {
return this.success(response.id, response.result, false);
}

Expand Down

0 comments on commit 3f49070

Please sign in to comment.