From c485693c1bb13da0e87e1198b87d50fc84e48769 Mon Sep 17 00:00:00 2001 From: AbhishekA1509 Date: Wed, 3 Jan 2024 19:05:56 +0530 Subject: [PATCH 1/4] feat: derive request timeout from env --- src/Common/Api.ts | 5 +++-- src/Common/Constants.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Common/Api.ts b/src/Common/Api.ts index 798e226d7..84004f0c4 100644 --- a/src/Common/Api.ts +++ b/src/Common/Api.ts @@ -1,5 +1,5 @@ import { ServerErrors } from './ServerError' -import { RequestTimeout, Host, URLS } from './Constants' +import { FALLBACK_REQUEST_TIMEOUT, Host, URLS } from './Constants' import { ResponseType, APIOptions } from './Types' const responseMessages = { @@ -176,7 +176,8 @@ function fetchInTime( const controller = new AbortController() const { signal } = controller const timeoutPromise: Promise = new Promise((resolve, reject) => { - let timeout = options?.timeout ? options.timeout : RequestTimeout + const requestTimeout = (window as any)?._env_?.GLOBAL_API_TIMEOUT ?? FALLBACK_REQUEST_TIMEOUT + let timeout = options?.timeout ? options.timeout : requestTimeout setTimeout(() => { controller.abort() reject({ diff --git a/src/Common/Constants.ts b/src/Common/Constants.ts index bc231a88b..71159bc65 100644 --- a/src/Common/Constants.ts +++ b/src/Common/Constants.ts @@ -1,6 +1,6 @@ import { RegistryTypeDetailType } from "./Types" -export const RequestTimeout = 60000 +export const FALLBACK_REQUEST_TIMEOUT = 60000 export const Host = process.env.REACT_APP_ORCHESTRATOR_ROOT export const DOCUMENTATION_HOME_PAGE = 'https://docs.devtron.ai' From 2ed89c511c3e485bc70e8687e34d16830b4255d5 Mon Sep 17 00:00:00 2001 From: AbhishekA1509 Date: Wed, 3 Jan 2024 19:06:30 +0530 Subject: [PATCH 2/4] chore: update package json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8794071c4..ea980d97e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.48", + "version": "0.0.48-beta-10", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { From bde17748acb02addace75a00d1376d3246c9f5a8 Mon Sep 17 00:00:00 2001 From: AbhishekA1509 Date: Thu, 4 Jan 2024 10:47:12 +0530 Subject: [PATCH 3/4] chore: update package json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea980d97e..0dc412623 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.48-beta-10", + "version": "0.0.49", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { From adfeee44e9316a3ede61a90e2710c501cd7e3033 Mon Sep 17 00:00:00 2001 From: AbhishekA1509 Date: Thu, 4 Jan 2024 10:49:13 +0530 Subject: [PATCH 4/4] chore: move timeout from let to const --- src/Common/Api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Common/Api.ts b/src/Common/Api.ts index 84004f0c4..7a722b2e4 100644 --- a/src/Common/Api.ts +++ b/src/Common/Api.ts @@ -177,7 +177,8 @@ function fetchInTime( const { signal } = controller const timeoutPromise: Promise = new Promise((resolve, reject) => { const requestTimeout = (window as any)?._env_?.GLOBAL_API_TIMEOUT ?? FALLBACK_REQUEST_TIMEOUT - let timeout = options?.timeout ? options.timeout : requestTimeout + const timeout = options?.timeout ? options.timeout : requestTimeout + setTimeout(() => { controller.abort() reject({