Skip to content

Commit

Permalink
Merge pull request #3266 from WalletConnect/refactor/try-catch-on-pay…
Browse files Browse the repository at this point in the history
…load

refactor: wrap try/catch on payload processing
  • Loading branch information
ganchoradkov authored Jul 27, 2023
2 parents eac72b9 + 8b8d61f commit 06ca6bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
19 changes: 12 additions & 7 deletions packages/core/src/controllers/pairing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,18 @@ export class Pairing implements IPairing {
if (this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(message))) return;

const payload = await this.core.crypto.decode(topic, message);
if (isJsonRpcRequest(payload)) {
this.core.history.set(topic, payload);
this.onRelayEventRequest({ topic, payload });
} else if (isJsonRpcResponse(payload)) {
await this.core.history.resolve(payload);
await this.onRelayEventResponse({ topic, payload });
this.core.history.delete(topic, payload.id);

try {
if (isJsonRpcRequest(payload)) {
this.core.history.set(topic, payload);
this.onRelayEventRequest({ topic, payload });
} else if (isJsonRpcResponse(payload)) {
await this.core.history.resolve(payload);
await this.onRelayEventResponse({ topic, payload });
this.core.history.delete(topic, payload.id);
}
} catch (error) {
this.logger.error(error);
}
});
}
Expand Down
23 changes: 13 additions & 10 deletions packages/sign-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,19 @@ export class Engine extends IEngine {
}

const payload = await this.client.core.crypto.decode(topic, message);

if (isJsonRpcRequest(payload)) {
this.client.core.history.set(topic, payload);
this.onRelayEventRequest({ topic, payload });
} else if (isJsonRpcResponse(payload)) {
await this.client.core.history.resolve(payload);
await this.onRelayEventResponse({ topic, payload });
this.client.core.history.delete(topic, payload.id);
} else {
this.onRelayEventUnknownPayload({ topic, payload });
try {
if (isJsonRpcRequest(payload)) {
this.client.core.history.set(topic, payload);
this.onRelayEventRequest({ topic, payload });
} else if (isJsonRpcResponse(payload)) {
await this.client.core.history.resolve(payload);
await this.onRelayEventResponse({ topic, payload });
this.client.core.history.delete(topic, payload.id);
} else {
this.onRelayEventUnknownPayload({ topic, payload });
}
} catch (error) {
this.client.logger.error(error);
}
},
);
Expand Down

0 comments on commit 06ca6bb

Please sign in to comment.