Skip to content

Commit

Permalink
fix: use object for error
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed May 21, 2019
1 parent 2d91e5a commit efd0f61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/RequestManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("client-js", () => {
transport.connection.on("message", () => {
fn(JSON.stringify({
jsonrpc: "2.0",
id: 1,
id: 3,
error: {
code: 0,
message: "out of order",
Expand All @@ -58,7 +58,13 @@ describe("client-js", () => {
});
};
c.connect();
expect(c.request("foo", [])).rejects.toThrow();
expect(c.request("foo", [])).rejects.toBe({
code: 0,
message: "out of order",
data: {
foo: "bar",
},
});
});

});
10 changes: 2 additions & 8 deletions src/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,9 @@ class RequestManager {
// call request callback for id
if (req) {
if (parsedData.error) {
req.reject(new Error(
[
`code: ${parsedData.error.code}`,
`message: ${parsedData.error.message}`,
`data: ${JSON.stringify(parsedData.error.data)}`,
].join("\n"),
));
req.reject(parsedData.error);
} else {
req.resolve(parsedData);
req.resolve(parsedData.result);
}
delete this.requests[parsedData.id];
}
Expand Down

0 comments on commit efd0f61

Please sign in to comment.