Update error handling when dialing libp2p connecion (#51)

This commit is contained in:
Pavel
2021-06-03 15:29:12 +03:00
committed by GitHub
parent b5bdc5d6e5
commit c01c6478b7

View File

@ -54,15 +54,6 @@ export interface FluenceConnectionOptions {
dialTimeout?: number; dialTimeout?: number;
} }
export class VersionIncompatibleError extends Error {
__proto__: Error;
constructor() {
const trueProto = new.target.prototype;
super('Current version of JS SDK is incompatible with the connected Fluence node. Please update JS SDK');
this.__proto__ = trueProto;
}
}
export class FluenceConnection { export class FluenceConnection {
private readonly selfPeerId: PeerId; private readonly selfPeerId: PeerId;
private node: Peer; private node: Peer;
@ -128,8 +119,11 @@ export class FluenceConnection {
try { try {
await this.node.dial(this.address); await this.node.dial(this.address);
} catch (e) { } catch (e) {
if (e.name === 'AggregateError' && e._errors[0].code === 'ERR_ENCRYPTION_FAILED') { if (e.name === 'AggregateError' && e._errors.length === 1) {
throw new VersionIncompatibleError(); const error = e._errors[0];
throw `Error dialing node ${this.address}:\n${error.code}\n${error.message}`;
} else {
throw e;
} }
} }