diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 064d8552b3..5d13350a31 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -81,7 +81,7 @@ export default class Rpc implements RpcInterface { return `${method} (${inputs}): ${type}`; } - private createInterface ({ methods, section }: RpcSection): RpcInterface$Section { + private createInterface ({ methods }: RpcSection): RpcInterface$Section { return Object .keys(methods) .reduce((exposed, method) => { diff --git a/packages/rpc-rx/src/index.ts b/packages/rpc-rx/src/index.ts index c7048b599d..a223bf6b08 100644 --- a/packages/rpc-rx/src/index.ts +++ b/packages/rpc-rx/src/index.ts @@ -8,7 +8,7 @@ import { RpcRxInterface, RpcRxInterface$Events, RpcRxInterface$Section } from '. import EventEmitter from 'eventemitter3'; import { BehaviorSubject, Observable, Subscriber, from } from 'rxjs'; -import { publishReplay, refCount } from 'rxjs/operators'; +import { map, publishReplay, refCount } from 'rxjs/operators'; import Rpc from '@polkadot/rpc-core/index'; import { isFunction, isUndefined } from '@polkadot/util'; @@ -134,20 +134,22 @@ export default class RpcRx implements RpcRxInterface { private createReplay (name: string, params: Array, section: RpcInterface$Section, subName: string, paramStr: string): Observable { return Observable .create((observer: Subscriber): Function => { - try { - const fn = section[name]; - const subscribe = fn(...params, this.createReplayCallback(observer)); + const fn = section[name]; + const callback = this.createReplayCallback(observer); + const subscribe = fn(...params, callback).catch((error) => + observer.next(error) + ); - return this.createReplayUnsub(fn, subscribe, subName, paramStr); - } catch (error) { - console.error(error); - - return (): void => { - console.error('Unsubscribe called on previously failed subscription', error); - }; - } + return this.createReplayUnsub(fn, subscribe, subName, paramStr); }) .pipe( + map((value) => { + if (value instanceof Error) { + throw value; + } + + return value; + }), publishReplay(1), refCount() );