Skip to content

Commit 053b654

Browse files
committed
feat!: return REMOTE_PEER_REJECTED if remote peer rejected the message
1 parent 6807185 commit 053b654

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

packages/core/src/lib/light_push/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,19 @@ class LightPush extends BaseProtocol implements ILightPush {
146146
return { recipients, error: SendError.DECODE_FAILED };
147147
}
148148

149-
if (response?.isSuccess) {
150-
recipients.some((recipient) => recipient.equals(peer.id)) ||
151-
recipients.push(peer.id);
152-
} else {
149+
if (!response) {
153150
log("Remote peer fault: No response in PushRPC");
154151
return { recipients, error: SendError.REMOTE_PEER_FAULT };
155152
}
156153

154+
if (!response.isSuccess) {
155+
log("Remote peer rejected the message: ", response.info);
156+
return { recipients, error: SendError.REMOTE_PEER_REJECTED };
157+
}
158+
159+
recipients.some((recipient) => recipient.equals(peer.id)) ||
160+
recipients.push(peer.id);
161+
157162
return { recipients };
158163
});
159164

packages/interfaces/src/protocols.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ export enum SendError {
7979
*/
8080
NO_PEER_AVAILABLE = "No peer available",
8181
/**
82-
* The remote peer did not behave as expected. Mitigation from `NO_PEER_AVAILABLE`
82+
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
8383
* or `DECODE_FAILED` can be used.
8484
*/
85-
REMOTE_PEER_FAULT = "Remote peer fault"
85+
REMOTE_PEER_FAULT = "Remote peer fault",
86+
/**
87+
* The remote peer rejected the message. Information provided by the remote peer
88+
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
89+
* or `DECODE_FAILED` can be used.
90+
*/
91+
REMOTE_PEER_REJECTED = "Remote peer rejected"
8692
}
8793

8894
export interface SendResult {

packages/tests/tests/light-push/index.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe("Waku Light Push [node only]", function () {
8686
});
8787
} else {
8888
expect(pushResponse.recipients.length).to.eq(0);
89-
expect(pushResponse.errors).to.include(SendError.NO_RPC_RESPONSE);
89+
expect(pushResponse.errors).to.include(SendError.REMOTE_PEER_REJECTED);
9090
expect(await messageCollector.waitForMessages(1)).to.eq(false);
9191
}
9292
});
@@ -158,7 +158,7 @@ describe("Waku Light Push [node only]", function () {
158158
});
159159
} else {
160160
expect(pushResponse.recipients.length).to.eq(0);
161-
expect(pushResponse.errors).to.include(SendError.NO_RPC_RESPONSE);
161+
expect(pushResponse.errors).to.include(SendError.REMOTE_PEER_REJECTED);
162162
expect(await messageCollector.waitForMessages(1)).to.eq(false);
163163
}
164164
});

0 commit comments

Comments
 (0)