Expose provider errors & .stats on API (#4878)

* Expose provider errors & .stats on API

* Expose WS errors
This commit is contained in:
Jaco
2022-05-31 10:24:17 +03:00
committed by GitHub
parent a7a5a409d8
commit e7beb2d46f
5 changed files with 25 additions and 2 deletions
+2 -1
View File
@@ -56,7 +56,7 @@ export class HttpProvider implements ProviderInterface {
this.#headers = headers;
this.#stats = {
active: { requests: 0, subscriptions: 0 },
total: { bytesRecv: 0, bytesSent: 0, cached: 0, requests: 0, subscriptions: 0, timeout: 0 }
total: { bytesRecv: 0, bytesSent: 0, cached: 0, errors: 0, requests: 0, subscriptions: 0, timeout: 0 }
};
}
@@ -169,6 +169,7 @@ export class HttpProvider implements ProviderInterface {
return decoded;
} catch (e) {
this.#stats.active.requests--;
this.#stats.total.errors++;
throw e;
}
+1
View File
@@ -71,6 +71,7 @@ export interface ProviderStats {
bytesRecv: number;
bytesSent: number;
cached: number;
errors: number;
requests: number;
subscriptions: number;
timeout: number;
+7 -1
View File
@@ -137,7 +137,7 @@ export class WsProvider implements ProviderInterface {
this.#websocket = null;
this.#stats = {
active: { requests: 0, subscriptions: 0 },
total: { bytesRecv: 0, bytesSent: 0, cached: 0, requests: 0, subscriptions: 0, timeout: 0 }
total: { bytesRecv: 0, bytesSent: 0, cached: 0, errors: 0, requests: 0, subscriptions: 0, timeout: 0 }
};
this.#timeout = timeout || DEFAULT_TIMEOUT_MS;
@@ -339,6 +339,8 @@ export class WsProvider implements ProviderInterface {
this.#stats.total.bytesSent += body.length;
this.#websocket.send(body);
} catch (error) {
this.#stats.total.errors++;
reject(error);
}
});
@@ -492,6 +494,8 @@ export class WsProvider implements ProviderInterface {
}
}
} catch (error) {
this.#stats.total.errors++;
handler.callback(error as Error, undefined);
}
@@ -520,6 +524,8 @@ export class WsProvider implements ProviderInterface {
handler.callback(null, result);
} catch (error) {
this.#stats.total.errors++;
handler.callback(error as Error, undefined);
}
};