Skip to content

Commit

Permalink
Merge pull request #233 from open-rpc/fix/ignore-missing-id
Browse files Browse the repository at this point in the history
fix(RequestManager): ignore missing id
  • Loading branch information
shanejonas authored Dec 17, 2020
2 parents 7c7c34d + 6bc8116 commit 473a908
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 7 additions & 11 deletions src/transports/TransportRequestManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ describe("Transport Request Manager", () => {
transportReqMan.addRequest(request, undefined);
});

it("should error on missing id to resolve", () => {
it("should not error on missing id to resolve", () => {
const payload = JSON.stringify(reqData.generateMockResponse(9, "haha"));
const err = transportReqMan.resolveResponse(payload, false) as Error;
expect(err.message).toContain("Could not resolve");
const res = transportReqMan.resolveResponse(payload, false);
expect(res).toBeUndefined();
});

it("should error on missing id but error response", () => {
Expand All @@ -60,14 +60,10 @@ describe("Transport Request Manager", () => {
expect(err.message).toContain("Error message");
});

it("should error on missing id to resolve and emit error", (done) => {
transportReqMan.transportEventChannel.on("error", (e) => {
expect(e.message).toContain("Could not resolve");
done();
});
it("should ignore on missing id", () => {
const payload = JSON.stringify(reqData.generateMockResponse(9, "haha"));
const err = transportReqMan.resolveResponse(payload) as Error;
expect(err.message).toContain("Could not resolve");
expect(err).toBeUndefined();
});

it("should add and reject pending requests", async () => {
Expand Down Expand Up @@ -143,7 +139,7 @@ describe("Transport Request Manager", () => {
transportReqMan.resolveResponse(JSON.stringify(res), false);
});

it("should emit response on batch request && reject invalid response", () => {
it("should emit response on batch request && ignore invalid response", () => {
const res = reqData.generateMockResponse(2, "hello");
// Add request to queue
const requestData = {
Expand All @@ -162,7 +158,7 @@ describe("Transport Request Manager", () => {

// Resolve pending request;
const err = transportReqMan.resolveResponse(JSON.stringify([res]), false) as Error;
expect(err.message).toContain("Could not resolve");
expect(err).toBeUndefined();
});

it("should emit notification on notification response", (done) => {
Expand Down
4 changes: 2 additions & 2 deletions src/transports/TransportRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ export class TransportRequestManager {
this.transportEventChannel.emit("notification", data as IJSONRPCNotificationResponse);
return;
}
let err = new JSONRPCError(`Could not resolve ${id}`, ERR_MISSIING_ID);
let err;
if (error) {
err = convertJSONToRPCError(data);
}
if (emitError) {
if (emitError && error && err) {
this.transportEventChannel.emit("error", err);
}
return err;
Expand Down

0 comments on commit 473a908

Please sign in to comment.