Catch errors while subscribing (#385)
This commit is contained in:
@@ -81,7 +81,7 @@ export default class Rpc implements RpcInterface {
|
|||||||
return `${method} (${inputs}): ${type}`;
|
return `${method} (${inputs}): ${type}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private createInterface ({ methods, section }: RpcSection): RpcInterface$Section {
|
private createInterface ({ methods }: RpcSection): RpcInterface$Section {
|
||||||
return Object
|
return Object
|
||||||
.keys(methods)
|
.keys(methods)
|
||||||
.reduce((exposed, method) => {
|
.reduce((exposed, method) => {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { RpcRxInterface, RpcRxInterface$Events, RpcRxInterface$Section } from '.
|
|||||||
|
|
||||||
import EventEmitter from 'eventemitter3';
|
import EventEmitter from 'eventemitter3';
|
||||||
import { BehaviorSubject, Observable, Subscriber, from } from 'rxjs';
|
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 Rpc from '@polkadot/rpc-core/index';
|
||||||
import { isFunction, isUndefined } from '@polkadot/util';
|
import { isFunction, isUndefined } from '@polkadot/util';
|
||||||
|
|
||||||
@@ -134,20 +134,22 @@ export default class RpcRx implements RpcRxInterface {
|
|||||||
private createReplay (name: string, params: Array<any>, section: RpcInterface$Section, subName: string, paramStr: string): Observable<any> {
|
private createReplay (name: string, params: Array<any>, section: RpcInterface$Section, subName: string, paramStr: string): Observable<any> {
|
||||||
return Observable
|
return Observable
|
||||||
.create((observer: Subscriber<any>): Function => {
|
.create((observer: Subscriber<any>): Function => {
|
||||||
try {
|
const fn = section[name];
|
||||||
const fn = section[name];
|
const callback = this.createReplayCallback(observer);
|
||||||
const subscribe = fn(...params, this.createReplayCallback(observer));
|
const subscribe = fn(...params, callback).catch((error) =>
|
||||||
|
observer.next(error)
|
||||||
|
);
|
||||||
|
|
||||||
return this.createReplayUnsub(fn, subscribe, subName, paramStr);
|
return this.createReplayUnsub(fn, subscribe, subName, paramStr);
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
|
|
||||||
return (): void => {
|
|
||||||
console.error('Unsubscribe called on previously failed subscription', error);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.pipe(
|
.pipe(
|
||||||
|
map((value) => {
|
||||||
|
if (value instanceof Error) {
|
||||||
|
throw value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}),
|
||||||
publishReplay(1),
|
publishReplay(1),
|
||||||
refCount()
|
refCount()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user