Improvements (#44)

* Add more detailed information when the particle is sent to incorrect peers

* Throwing custom error in case of version incompatibility
This commit is contained in:
Pavel
2021-04-27 17:08:18 +03:00
committed by GitHub
parent d84d9fd7ea
commit 8c372cd0c8
4 changed files with 50 additions and 14 deletions

View File

@ -66,6 +66,7 @@ export class RequestFlow {
const interpreterOutcome = this.runInterpreter(interpreter);
log.debug('inner interpreter outcome:', {
particleId: this.getParticle()?.id,
ret_code: interpreterOutcome.ret_code,
error_message: interpreterOutcome.error_message,
next_peer_pks: interpreterOutcome.next_peer_pks,
@ -86,25 +87,31 @@ export class RequestFlow {
// we only expect a single possible peer id to send particle further
if (nextPeers.length > 1) {
throw new Error(
'Particle is expected to be sent to only the single peer (relay which client is connected to)',
);
this.throwIncorrectNextPeerPks(nextPeers);
}
// this peer id must be the relay, the client is connected to
if (!relayPeerId || nextPeers[0] !== relayPeerId) {
throw new Error(
'Particle is expected to be sent to only the single peer (relay which client is connected to)',
);
this.throwIncorrectNextPeerPks(nextPeers);
}
if (!connection) {
throw new Error('Cannot send particle: non connected');
this.raiseError('Cannot send particle: non connected');
}
this.sendIntoConnection(connection);
}
private throwIncorrectNextPeerPks(nextPeers: PeerIdB58[]) {
this.raiseError(
`Particle is expected to be sent to only the single peer (relay which client is connected to).
particle id: ${this.getParticle()?.id}
next peers: ${nextPeers.join(' ')}
relay peer id: ${this.relayPeerId}
`,
);
}
async initState(peerId: PeerId): Promise<void> {
const id = this.id;
let currentTime = Date.now();