Skip to content

Commit

Permalink
add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Aug 17, 2023
1 parent 6a17cc3 commit befbd37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 21 additions & 12 deletions packages/core/src/lib/light_push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,35 @@ class LightPush extends BaseProtocol implements ILightPush {
const { pubSubTopic = DefaultPubSubTopic } = this.options;

const recipients: PeerId[] = [];
let query: PushRpc;

try {
if (!isSizeValid(message.payload)) {
log("Failed to send waku light push: message is bigger than 1MB");
return {
recipients,
errors: [SendError.SIZE_TOO_BIG]
};
}

if (!isSizeValid(message.payload)) {
log("Failed to send waku light push: message is bigger than 1MB");
return {
recipients,
errors: [SendError.SIZE_TOO_BIG]
};
}
const protoMessage = await encoder.toProtoObj(message);
if (!protoMessage) {
log("Failed to encode to protoMessage, aborting push");
return {
recipients,
errors: [SendError.ENCODE_FAILED]
};
}

const protoMessage = await encoder.toProtoObj(message);
if (!protoMessage) {
log("Failed to encode to protoMessage, aborting push");
query = PushRpc.createRequest(protoMessage, pubSubTopic);
} catch (error) {
log("Failed to encode to protoMessage", error);
return {
recipients,
errors: [SendError.ENCODE_FAILED]
};
}

const query = PushRpc.createRequest(protoMessage, pubSubTopic);

const peers = await this.getPeers(3, true, opts?.peerId && [opts?.peerId]);

const promises = peers.map(async (peer) => {
Expand Down

0 comments on commit befbd37

Please sign in to comment.