mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-28 15:21:33 +00:00
Update error handling when dialing libp2p connecion (#51)
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user