Added debug event info to WebSocketProvider (#1018).

This commit is contained in:
Richard Moore 2020-10-06 21:12:49 -04:00
parent ef8e4330d3
commit 8e682cc848
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651

@ -95,15 +95,32 @@ export class WebSocketProvider extends JsonRpcProvider {
if (result.result !== undefined) {
request.callback(null, result.result);
this.emit("debug", {
action: "response",
request: JSON.parse(request.payload),
response: result.result,
provider: this
});
} else {
let error: Error = null;
if (result.error) {
const error: any = new Error(result.error.message || "unknown error");
defineReadOnly(error, "code", result.error.code || null);
defineReadOnly(error, "response", data);
request.callback(error, undefined);
error = new Error(result.error.message || "unknown error");
defineReadOnly(<any>error, "code", result.error.code || null);
defineReadOnly(<any>error, "response", data);
} else {
request.callback(new Error("unknown error"), undefined);
error = new Error("unknown error");
}
request.callback(error, undefined);
this.emit("debug", {
action: "response",
error: error,
request: JSON.parse(request.payload),
provider: this
});
}
} else if (result.method === "eth_subscription") {
@ -176,6 +193,12 @@ export class WebSocketProvider extends JsonRpcProvider {
jsonrpc: "2.0"
});
this.emit("debug", {
action: "request",
request: JSON.parse(payload),
provider: this
});
this._requests[String(rid)] = { callback, payload };
if (this._wsReady) { this._websocket.send(payload); }