MCPcopy Create free account
hub / github.com/Effect-TS/effect / runRequest

Function runRequest

packages/effect/src/unstable/http/HttpClient.ts:1201–1222  ·  view source on GitHub ↗
(adaptive: RateLimiter.AdaptiveConsumeResult | undefined)

Source from the content-addressed store, hash-verified

1199 R
1200 > => {
1201 const runRequest = (adaptive: RateLimiter.AdaptiveConsumeResult | undefined) => {
1202 const request = Effect.matchEffect(effect, {
1203 onSuccess(response) {
1204 return Effect.flatMap(inspectResponse(response, adaptive), (retryAfter) => {
1205 if (response.status !== 429 || !canRetry) return Effect.succeed(response)
1206 return retry(retryAfter)
1207 })
1208 },
1209 onFailure(error) {
1210 if (isTooManyRequestsHttpClientError(error)) {
1211 return Effect.flatMap(
1212 inspectResponse(error.reason.response, adaptive),
1213 (retryAfter) => canRetry ? retry(retryAfter) : Effect.fail(error)
1214 )
1215 }
1216 return Effect.fail(error)
1217 }
1218 })
1219 return adaptive === undefined || Duration.isZero(adaptive.delay)
1220 ? request
1221 : Effect.delay(request, adaptive.delay)
1222 }
1223 if (!adaptiveLearningEnabled) {
1224 return runRequest(undefined)
1225 }

Callers 1

runAdaptiveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected