Allow for string subids (#2335)

This commit is contained in:
Jaco Greeff
2020-06-07 19:16:16 +02:00
committed by GitHub
parent 15b80a47c3
commit 7310ea825e
3 changed files with 14 additions and 2 deletions
@@ -48,6 +48,18 @@ describe('decodeResponse', (): void => {
).toThrow(/123: test error: Some random error description/);
});
it('allows for number subscription ids', (): void => {
expect(
coder.decodeResponse({ id: 1, jsonrpc: '2.0', method: 'test', params: { result: 'test result', subscription: 1 } } as JsonRpcResponse)
).toEqual('test result');
});
it('allows for string subscription ids', (): void => {
expect(
coder.decodeResponse({ id: 1, jsonrpc: '2.0', method: 'test', params: { result: 'test result', subscription: 'abc' } } as JsonRpcResponse)
).toEqual('test result');
});
it('returns the result', (): void => {
expect(
coder.decodeResponse({ id: 1, jsonrpc: '2.0', result: 'some result' } as JsonRpcResponse)
+1 -1
View File
@@ -30,7 +30,7 @@ export default class RpcCoder {
const isSubscription = !isUndefined(response.params) && !isUndefined(response.method);
assert(isNumber(response.id) || (isSubscription && isNumber(response.params.subscription)), 'Invalid id field in decoded object');
assert(isNumber(response.id) || (isSubscription && (isNumber(response.params.subscription) || isString(response.params.subscription))), 'Invalid id field in decoded object');
this._checkError(response.error);