Skip to content

Commit

Permalink
Added error event to provider (#3970, #3982).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 24, 2023
1 parent e848978 commit af0291c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export type DebugEventAbstractProvider = {

// Only sub-classes overriding the _getSubscription method will care about this
export type Subscription = {
type: "block" | "close" | "debug" | "network" | "pending",
type: "block" | "close" | "debug" | "error" | "network" | "pending",
tag: string
} | {
type: "transaction",
Expand Down Expand Up @@ -186,7 +186,7 @@ async function getSubscription(_event: ProviderEvent, provider: AbstractProvider

if (typeof(_event) === "string") {
switch (_event) {
case "block": case "pending": case "debug": case "network": {
case "block": case "pending": case "debug": case "error": case "network": {
return { type: _event, tag: _event };
}
}
Expand Down Expand Up @@ -997,6 +997,7 @@ export class AbstractProvider implements Provider {
if (check !== address) { return null; }

return name;

} catch (error) {
// No data was returned from the resolver
if (isError(error, "BAD_DATA") && error.value === "0x") {
Expand Down Expand Up @@ -1094,6 +1095,7 @@ export class AbstractProvider implements Provider {
_getSubscriber(sub: Subscription): Subscriber {
switch (sub.type) {
case "debug":
case "error":
case "network":
return new UnmanagedSubscriber(sub.type);
case "block":
Expand Down
19 changes: 5 additions & 14 deletions src.ts/providers/provider-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import { UnmanagedSubscriber } from "./abstract-provider.js";
import { assert, assertArgument } from "../utils/index.js";
import { assert, assertArgument, makeError } from "../utils/index.js";
import { JsonRpcApiProvider } from "./provider-jsonrpc.js";

import type { Subscriber, Subscription } from "./abstract-provider.js";
Expand Down Expand Up @@ -234,25 +234,16 @@ export class SocketProvider extends JsonRpcApiProvider {
if ("id" in result) {
const callback = this.#callbacks.get(result.id);
if (callback == null) {
console.log("Weird... Response for not a thing we sent");
this.emit("error", makeError("received result for unknown id", "UNKNOWN_ERROR", {
reasonCode: "UNKNOWN_ID",
result
}));
return;
}
this.#callbacks.delete(result.id);

callback.resolve(result);

/*
if ("error" in result) {
const { message, code, data } = result.error;
const error = makeError(message || "unkonwn error", "SERVER_ERROR", {
request: `ws:${ JSON.stringify(callback.payload) }`,
info: { code, data }
});
callback.reject(error);
} else {
callback.resolve(result.result);
}
*/
} else if (result.method === "eth_subscription") {
const filterId = result.params.subscription;
const subscriber = this.#subs.get(filterId);
Expand Down

0 comments on commit af0291c

Please sign in to comment.