Merged in feat/sw-3006-timeout-fetch (pull request #2335)
feat(SW-3006): added default timeout to all requests * feat(sw-3006): added default timeout to all requests * Fixed spreading Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -55,6 +55,7 @@ export async function GET(
|
|||||||
).toString(),
|
).toString(),
|
||||||
client_id: env.SAS_AUTH_CLIENTID,
|
client_id: env.SAS_AUTH_CLIENTID,
|
||||||
}),
|
}),
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ async function refreshTokens(token: JWT) {
|
|||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
})
|
})
|
||||||
|
|
||||||
const new_tokens = await response.json()
|
const new_tokens = await response.json()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const defaultOptions: RequestInit = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wrappedFetch = fetchRetry(fetch, {
|
const wrappedFetch = fetchRetry(fetch, {
|
||||||
retries: 3,
|
retries: 2,
|
||||||
retryDelay: function (attempt) {
|
retryDelay: function (attempt) {
|
||||||
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
||||||
},
|
},
|
||||||
@@ -35,10 +35,11 @@ export async function get(
|
|||||||
const url = new URL(env.API_BASEURL)
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
url.search = new URLSearchParams(params).toString()
|
url.search = new URLSearchParams(params).toString()
|
||||||
return wrappedFetch(
|
|
||||||
url,
|
return wrappedFetch(url, {
|
||||||
merge.all([defaultOptions, { method: "GET" }, options])
|
...merge.all([defaultOptions, { method: "GET" }, options]),
|
||||||
)
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function patch(
|
export async function patch(
|
||||||
@@ -50,14 +51,14 @@ export async function patch(
|
|||||||
const url = new URL(env.API_BASEURL)
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
url.search = new URLSearchParams(params).toString()
|
url.search = new URLSearchParams(params).toString()
|
||||||
return wrappedFetch(
|
return wrappedFetch(url, {
|
||||||
url,
|
...merge.all([
|
||||||
merge.all([
|
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
{ body: JSON.stringify(body), method: "PATCH" },
|
{ body: JSON.stringify(body), method: "PATCH" },
|
||||||
requestOptions,
|
requestOptions,
|
||||||
])
|
]),
|
||||||
)
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function post(
|
export async function post(
|
||||||
@@ -69,14 +70,14 @@ export async function post(
|
|||||||
const url = new URL(env.API_BASEURL)
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
url.search = new URLSearchParams(params).toString()
|
url.search = new URLSearchParams(params).toString()
|
||||||
return wrappedFetch(
|
return wrappedFetch(url, {
|
||||||
url,
|
...merge.all([
|
||||||
merge.all([
|
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
{ body: JSON.stringify(body), method: "POST" },
|
{ body: JSON.stringify(body), method: "POST" },
|
||||||
requestOptions,
|
requestOptions,
|
||||||
])
|
]),
|
||||||
)
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function put(
|
export async function put(
|
||||||
@@ -88,14 +89,14 @@ export async function put(
|
|||||||
const url = new URL(env.API_BASEURL)
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
url.search = new URLSearchParams(params).toString()
|
url.search = new URLSearchParams(params).toString()
|
||||||
return wrappedFetch(
|
return wrappedFetch(url, {
|
||||||
url,
|
...merge.all([
|
||||||
merge.all([
|
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
{ body: JSON.stringify(body), method: "PUT" },
|
{ body: JSON.stringify(body), method: "PUT" },
|
||||||
requestOptions,
|
requestOptions,
|
||||||
])
|
]),
|
||||||
)
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function remove(
|
export async function remove(
|
||||||
@@ -107,12 +108,12 @@ export async function remove(
|
|||||||
const url = new URL(env.API_BASEURL)
|
const url = new URL(env.API_BASEURL)
|
||||||
url.pathname = endpoint
|
url.pathname = endpoint
|
||||||
url.search = new URLSearchParams(params).toString()
|
url.search = new URLSearchParams(params).toString()
|
||||||
return wrappedFetch(
|
return wrappedFetch(url, {
|
||||||
url,
|
...merge.all([
|
||||||
merge.all([
|
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
{ body: JSON.stringify(body), method: "DELETE" },
|
{ body: JSON.stringify(body), method: "DELETE" },
|
||||||
requestOptions,
|
requestOptions,
|
||||||
])
|
]),
|
||||||
)
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,12 +73,15 @@ function internalRequest<T>(
|
|||||||
params?: RequestInit
|
params?: RequestInit
|
||||||
) {
|
) {
|
||||||
const wrappedFetch = fetchRetry(fetch, {
|
const wrappedFetch = fetchRetry(fetch, {
|
||||||
retries: 3,
|
retries: 2,
|
||||||
retryDelay: function (attempt) {
|
retryDelay: function (attempt) {
|
||||||
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
return Math.pow(2, attempt) * 150 // 150, 300, 600
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return wrappedFetch(url, params)
|
return wrappedFetch(url, {
|
||||||
|
...params,
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ async function fetchAndCacheRedirect(lang: Lang, pathname: string) {
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ async function fetchAndCacheRedirect(lang: Lang, pathname: string) {
|
|||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
// longer once tested
|
// longer once tested
|
||||||
"1m"
|
"1d"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default async (request: Request, _context: Context) => {
|
|||||||
)
|
)
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers,
|
headers,
|
||||||
|
signal: AbortSignal.timeout(30_000),
|
||||||
})
|
})
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text()
|
const text = await response.text()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default async (request: Request, _context: Context) => {
|
|||||||
)
|
)
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers,
|
headers,
|
||||||
|
signal: AbortSignal.timeout(30_000),
|
||||||
})
|
})
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text()
|
const text = await response.text()
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ async function callWarmup(key: WarmupFunctionsKey, context: Context) {
|
|||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
Authorization: `Bearer ${warmupToken}`,
|
Authorization: `Bearer ${warmupToken}`,
|
||||||
},
|
},
|
||||||
|
signal: AbortSignal.timeout(30_000),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export async function warmupHotelDataOnLang(lang: Lang) {
|
|||||||
`${PUBLIC_URL}/api/hoteldata?lang=${lang}`,
|
`${PUBLIC_URL}/api/hoteldata?lang=${lang}`,
|
||||||
{
|
{
|
||||||
headers: { cache: "no-store" },
|
headers: { cache: "no-store" },
|
||||||
|
signal: AbortSignal.timeout(30_000),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -880,7 +880,9 @@ export const hotelQueryRouter = router({
|
|||||||
`coordinates:${address}`,
|
`coordinates:${address}`,
|
||||||
async function () {
|
async function () {
|
||||||
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${apiKey}`
|
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${apiKey}`
|
||||||
const response = await fetch(url)
|
const response = await fetch(url, {
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
|
})
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
if (data.status !== "OK") {
|
if (data.status !== "OK") {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export const jobylonQueryRouter = router({
|
|||||||
async () => {
|
async () => {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
cache: "no-cache",
|
cache: "no-cache",
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ async function fetchRequestOtp({ sasAuthToken }: { sasAuthToken: string }) {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
referenceId: uuidv4(),
|
referenceId: uuidv4(),
|
||||||
}),
|
}),
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ async function fetchVerifyOtp(input: z.infer<typeof inputSchema>) {
|
|||||||
otpCode: input.otp,
|
otpCode: input.otp,
|
||||||
databaseUUID: databaseUUID,
|
databaseUUID: databaseUUID,
|
||||||
}),
|
}),
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ async function fetchServiceToken(scopes: string[]) {
|
|||||||
client_secret: env.CURITY_CLIENT_SECRET_SERVICE,
|
client_secret: env.CURITY_CLIENT_SECRET_SERVICE,
|
||||||
scope: scopes.join(" "),
|
scope: scopes.join(" "),
|
||||||
}),
|
}),
|
||||||
|
signal: AbortSignal.timeout(15_000),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user