mirror of
https://github.com/status-im/js-waku.git
synced 2025-02-23 10:28:15 +00:00
feat(lightpush)!: return new error messages (#2115)
* feat: return new error messages * fix test, remove unused * up * up * rollback * up test
This commit is contained in:
parent
eadb85ab83
commit
a022433851
@ -121,7 +121,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: ProtocolError.REMOTE_PEER_FAULT,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peer.id
|
peerId: peer.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -170,7 +170,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|||||||
if (!res || !res.length) {
|
if (!res || !res.length) {
|
||||||
return {
|
return {
|
||||||
failure: {
|
failure: {
|
||||||
error: ProtocolError.REMOTE_PEER_FAULT,
|
error: ProtocolError.NO_RESPONSE,
|
||||||
peerId: peer.id
|
peerId: peer.id
|
||||||
},
|
},
|
||||||
success: null
|
success: null
|
||||||
@ -211,7 +211,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: ProtocolError.REMOTE_PEER_FAULT,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peer.id
|
peerId: peer.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -243,7 +243,7 @@ export class FilterCore extends BaseProtocol implements IBaseProtocolCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: ProtocolError.REMOTE_PEER_FAULT,
|
error: ProtocolError.NO_RESPONSE,
|
||||||
peerId: peer.id
|
peerId: peer.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -20,6 +20,7 @@ import { Uint8ArrayList } from "uint8arraylist";
|
|||||||
import { BaseProtocol } from "../base_protocol.js";
|
import { BaseProtocol } from "../base_protocol.js";
|
||||||
|
|
||||||
import { PushRpc } from "./push_rpc.js";
|
import { PushRpc } from "./push_rpc.js";
|
||||||
|
import { isRLNResponseError, matchRLNErrorMessage } from "./utils.js";
|
||||||
|
|
||||||
const log = new Logger("light-push");
|
const log = new Logger("light-push");
|
||||||
|
|
||||||
@ -153,7 +154,19 @@ export class LightPushCore extends BaseProtocol implements IBaseProtocolCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: ProtocolError.REMOTE_PEER_FAULT,
|
error: ProtocolError.NO_RESPONSE,
|
||||||
|
peerId: peer.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRLNResponseError(response.info)) {
|
||||||
|
const rlnErrorCase = matchRLNErrorMessage(response.info!);
|
||||||
|
log.error("Remote peer rejected the message: ", rlnErrorCase);
|
||||||
|
return {
|
||||||
|
success: null,
|
||||||
|
failure: {
|
||||||
|
error: rlnErrorCase,
|
||||||
peerId: peer.id
|
peerId: peer.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
31
packages/core/src/lib/light_push/utils.ts
Normal file
31
packages/core/src/lib/light_push/utils.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { ProtocolError } from "@waku/interfaces";
|
||||||
|
|
||||||
|
// should match nwaku
|
||||||
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/rln_relay.nim#L309
|
||||||
|
// https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim#L20
|
||||||
|
const RLN_GENERATION_PREFIX_ERROR = "could not generate rln-v2 proof";
|
||||||
|
|
||||||
|
export const isRLNResponseError = (info?: string): boolean => {
|
||||||
|
if (!info) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return info.includes(RLN_GENERATION_PREFIX_ERROR);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const matchRLNErrorMessage = (info: string): ProtocolError => {
|
||||||
|
const rlnErrorMap: { [key: string]: ProtocolError } = {
|
||||||
|
[ProtocolError.RLN_IDENTITY_MISSING]: ProtocolError.RLN_IDENTITY_MISSING,
|
||||||
|
[ProtocolError.RLN_MEMBERSHIP_INDEX]: ProtocolError.RLN_MEMBERSHIP_INDEX,
|
||||||
|
[ProtocolError.RLN_LIMIT_MISSING]: ProtocolError.RLN_LIMIT_MISSING
|
||||||
|
};
|
||||||
|
|
||||||
|
const infoLowerCase = info.toLowerCase();
|
||||||
|
for (const errorKey in rlnErrorMap) {
|
||||||
|
if (infoLowerCase.includes(errorKey.toLowerCase())) {
|
||||||
|
return rlnErrorMap[errorKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProtocolError.RLN_PROOF_GENERATION;
|
||||||
|
};
|
@ -179,7 +179,7 @@ export enum ProtocolError {
|
|||||||
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
|
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
|
||||||
* or `DECODE_FAILED` can be used.
|
* or `DECODE_FAILED` can be used.
|
||||||
*/
|
*/
|
||||||
REMOTE_PEER_FAULT = "Remote peer fault",
|
NO_RESPONSE = "No response received",
|
||||||
/**
|
/**
|
||||||
* The remote peer rejected the message. Information provided by the remote peer
|
* The remote peer rejected the message. Information provided by the remote peer
|
||||||
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
|
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
|
||||||
@ -190,7 +190,27 @@ export enum ProtocolError {
|
|||||||
* The protocol request timed out without a response. This may be due to a connection issue.
|
* The protocol request timed out without a response. This may be due to a connection issue.
|
||||||
* Mitigation can be: retrying after a given time period
|
* Mitigation can be: retrying after a given time period
|
||||||
*/
|
*/
|
||||||
REQUEST_TIMEOUT = "Request timeout"
|
REQUEST_TIMEOUT = "Request timeout",
|
||||||
|
/**
|
||||||
|
* Missing credentials info message.
|
||||||
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L186
|
||||||
|
*/
|
||||||
|
RLN_IDENTITY_MISSING = "Identity credentials are not set",
|
||||||
|
/**
|
||||||
|
* Membership index missing info message.
|
||||||
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L188
|
||||||
|
*/
|
||||||
|
RLN_MEMBERSHIP_INDEX = "Membership index is not set",
|
||||||
|
/**
|
||||||
|
* Message limit is missing.
|
||||||
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L190
|
||||||
|
*/
|
||||||
|
RLN_LIMIT_MISSING = "User message limit is not set",
|
||||||
|
/**
|
||||||
|
* General proof generation error message.
|
||||||
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
|
||||||
|
*/
|
||||||
|
RLN_PROOF_GENERATION = "Proof generation failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Failure {
|
export interface Failure {
|
||||||
|
@ -101,7 +101,7 @@ class LightPushSDK extends BaseProtocolSDK implements ILightPushSDK {
|
|||||||
failures.push(failure);
|
failures.push(failure);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("Failed to send message to peer", result.reason);
|
log.error("Failed unexpectedly while sending:", result.reason);
|
||||||
failures.push({ error: ProtocolError.GENERIC_FAIL });
|
failures.push({ error: ProtocolError.GENERIC_FAIL });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user