From ee7ad2ac7a59a74f5d91481ba34ff9294e7186e6 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Fri, 28 Jul 2023 20:58:46 +0200 Subject: [PATCH] Move fetch to @lodestar/api package --- packages/api/src/index.ts | 3 +++ packages/{utils/src => api/src/utils/client}/fetch.ts | 8 +++++++- packages/api/src/utils/client/httpClient.ts | 5 +++-- packages/api/src/utils/client/index.ts | 1 + .../test/unit => api/test/unit/client}/fetch.test.ts | 3 +-- packages/api/test/utils/fetchOpenApiSpec.ts | 2 +- .../beacon-node/src/eth1/provider/jsonRpcHttpClient.ts | 3 ++- packages/beacon-node/src/execution/engine/utils.ts | 2 +- packages/beacon-node/src/monitoring/service.ts | 3 ++- packages/beacon-node/test/e2e/api/impl/config.test.ts | 2 +- .../beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts | 2 +- .../beacon-node/test/unit/metrics/server/http.test.ts | 2 +- packages/utils/src/index.ts | 1 - packages/validator/src/util/externalSignerClient.ts | 2 +- 14 files changed, 25 insertions(+), 14 deletions(-) rename packages/{utils/src => api/src/utils/client}/fetch.ts (93%) rename packages/{utils/test/unit => api/test/unit/client}/fetch.test.ts (97%) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 5a8760f590a2..a0436611798e 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -10,6 +10,9 @@ export { HttpError, ApiError, Metrics, + FetchError, + isFetchError, + fetch, } from "./utils/client/index.js"; export * from "./utils/routes.js"; diff --git a/packages/utils/src/fetch.ts b/packages/api/src/utils/client/fetch.ts similarity index 93% rename from packages/utils/src/fetch.ts rename to packages/api/src/utils/client/fetch.ts index 0e5c37e1e270..49df361ffa19 100644 --- a/packages/utils/src/fetch.ts +++ b/packages/api/src/utils/client/fetch.ts @@ -1,5 +1,7 @@ /** - * Wrapper around native fetch to improve error handling + * Native fetch with transparent and consistent error handling + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/fetch) */ async function wrappedFetch(url: string | URL, init?: RequestInit): Promise { try { @@ -11,6 +13,10 @@ async function wrappedFetch(url: string | URL, init?: RequestInit): Promise