fix(bitbucket): preserve rate limits from optional PR reads (#12486)
This commit is contained in:
1 parent
bd5dc58c65
commit
eadeaf2282
4 files changed
+142
-10
No files matched your search
@@ -618,6 +618,30 @@ it.effect("preserves Bitbucket response body read failures as their immediate ca
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("keeps the 429 retry time when the response body cannot be read", () => {
|
||||
const { layer } = makeLayer({
|
||||
response: () =>
|
||||
new Response(
|
||||
new ReadableStream<Uint8Array>({
|
||||
start: (controller) => controller.error(new Error("response stream failed")),
|
||||
}),
|
||||
{ status: 429, headers: { "Retry-After": "120" } },
|
||||
),
|
||||
});
|
||||
|
||||
return Effect.gen(function* () {
|
||||
yield* TestClock.setTime(1_000);
|
||||
const bitbucket = yield* BitbucketApi.BitbucketApi;
|
||||
const error = yield* bitbucket
|
||||
.request({ method: "GET", url: "/repositories/acme/web" })
|
||||
.pipe(Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BitbucketApi.BitbucketResponseBodyReadError);
|
||||
assert.strictEqual(error.status, 429);
|
||||
assert.strictEqual(error.retryAt, 121_000);
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
|
||||
it.effect("checks out same-repository pull requests with the existing Bitbucket remote", () => {
|
||||
const { git, layer } = makeLayer({
|
||||
response: () =>
|
||||
|
||||
@@ -117,6 +117,7 @@ export class BitbucketResponseBodyReadError extends Schema.TaggedError<Bitbucket
|
||||
{
|
||||
operation: BitbucketApiOperation,
|
||||
status: Schema.Int,
|
||||
retryAt: Schema.optional(Schema.Number),
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
@@ -584,6 +585,7 @@ function responseError(
|
||||
// only its length is reported anyway.
|
||||
return Effect.gen(function* () {
|
||||
const now = yield* Clock.currentTimeMillis;
|
||||
const retryAt = retryAtFromHeader(response.headers["retry-after"], now);
|
||||
const collected = yield* collectUint8StreamText({
|
||||
stream: response.stream,
|
||||
maxBytes: DEFAULT_MAX_RESPONSE_BYTES,
|
||||
@@ -593,6 +595,7 @@ function responseError(
|
||||
new BitbucketResponseBodyReadError({
|
||||
operation,
|
||||
status: response.status,
|
||||
retryAt,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
@@ -601,7 +604,7 @@ function responseError(
|
||||
operation,
|
||||
status: response.status,
|
||||
responseBodyLength: collected.text.length,
|
||||
retryAt: retryAtFromHeader(response.headers["retry-after"], now),
|
||||
retryAt,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user