From 84c680436f2adf3a5f49e05a3011b56e3873b1c2 Mon Sep 17 00:00:00 2001 From: Keita Kobayashi Date: Wed, 23 Oct 2024 10:44:59 +0900 Subject: [PATCH] Remove internal retry logic --- src/config.ts | 42 +----------------------------------------- src/main-node.ts | 5 +---- src/normalize.ts | 9 --------- 3 files changed, 2 insertions(+), 54 deletions(-) diff --git a/src/config.ts b/src/config.ts index bc1670dd60..5ddfa0636d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,8 +7,6 @@ export const defaultEndpoint = export const currentConfig: Config = { japaneseAddressesApi: defaultEndpoint, cacheSize: 1_000, - backendTimeout: 1_500, - backendTries: 3, } export type FetchOptions = { @@ -27,44 +25,6 @@ export type FetchLike = ( options?: FetchOptions, ) => Promise -const timeoutableFetch = async ( - fetch: (input: RequestInfo, init?: RequestInit) => Promise, - input: RequestInfo, - init: RequestInit | undefined, - timeout: number, -) => { - const response = await fetch(input, { - ...init, - signal: AbortSignal.timeout(timeout), - }) - return response -} - -export async function fetchWithTimeoutRetry( - fetch: (input: RequestInfo, init?: RequestInit) => Promise, - input: RequestInfo, - init?: RequestInit, -) { - let tries = 0 - while (true) { - try { - // await needs to be in this try block, otherwise it won't be caught - const resp = await timeoutableFetch( - fetch, - input, - init, - currentConfig.backendTimeout, - ) - return resp - } catch (error) { - tries++ - if (tries >= currentConfig.backendTries) { - throw error - } - } - } -} - /** * @internal */ @@ -90,7 +50,7 @@ export const __internals: { fetch: FetchLike } = { } else { throw new Error('fetch is not available in this environment') } - return fetchWithTimeoutRetry(globalFetch, url, { + return globalFetch(url, { headers, }) }, diff --git a/src/main-node.ts b/src/main-node.ts index 1a53e5ef13..0a117b57f7 100644 --- a/src/main-node.ts +++ b/src/main-node.ts @@ -1,7 +1,6 @@ import * as Normalize from './normalize' import { __internals, - fetchWithTimeoutRetry, FetchOptions, FetchResponseLike, } from './config' @@ -48,9 +47,7 @@ export const requestHandlers = { if (typeof o.length !== 'undefined' && typeof o.offset !== 'undefined') { headers['Range'] = `bytes=${o.offset}-${o.offset + o.length - 1}` } - return fetchWithTimeoutRetry( - // 私達が使う場所の undici fetch インタフェースはDOMのfetchと同等なので、型キャストしても問題ない - fetch as unknown as (typeof Window.prototype)['fetch'], + return fetch( fileURL.toString(), { headers, diff --git a/src/normalize.ts b/src/normalize.ts index 0af6f1cd15..6836d25920 100755 --- a/src/normalize.ts +++ b/src/normalize.ts @@ -59,15 +59,6 @@ export interface Config { /** 内部キャッシュの最大サイズ。デフォルトでは 1,000 件 */ cacheSize: number - /** - * バックエンドへのリクエストのタイムアウト。 - * デフォルト 600ms - * タイムアウトした場合、数回リトライを行います。 - * リトライ回数は {@link backendTries} で設定します。 - */ - backendTimeout: number - backendTries: number - geoloniaApiKey?: string } export const config: Config = currentConfig