@@ -510,6 +510,58 @@ describe("GitHubRest", () => {
510510 } ) . pipe ( Effect . provide ( layer ) ) ;
511511 } ) ;
512512
513+ it . effect ( "reads a proxy's 403 with Retry-After as a refusal and keeps the host open" , ( ) => {
514+ const pages = [
515+ "<html><head><title>403 Forbidden</title></head><body>nginx</body></html>" ,
516+ "<html><body>Request blocked by proxy abuse detection; contact your administrator</body></html>" ,
517+ ] ;
518+ const { layer, requests } = harness (
519+ ( ) =>
520+ new Response ( pages . shift ( ) , {
521+ status : 403 ,
522+ headers : { "content-type" : "text/html" , "retry-after" : "5" } ,
523+ } ) ,
524+ ) ;
525+ return Effect . gen ( function * ( ) {
526+ yield * TestClock . setTime ( NOW ) ;
527+ const api = yield * GitHubRest . GitHubRest ;
528+ const read = {
529+ host : "ghes.example.internal" ,
530+ operation : "checks" ,
531+ path : "repos/acme/web/pulls/7" ,
532+ } ;
533+ const first = yield * Effect . flip ( api . rest ( read ) ) ;
534+ expect ( first ) . toMatchObject ( { _tag : "GitHubApiResponseError" , status : 403 } ) ;
535+ const second = yield * Effect . flip ( api . rest ( read ) ) ;
536+ expect ( second ) . toMatchObject ( { _tag : "GitHubApiResponseError" , status : 403 } ) ;
537+ expect ( requests ) . toHaveLength ( 2 ) ;
538+ } ) . pipe ( Effect . provide ( layer ) ) ;
539+ } ) ;
540+
541+ it . effect ( "pauses the host on an abuse-detection 403 that never says rate limit" , ( ) => {
542+ const { layer, requests } = harness ( ( ) =>
543+ json (
544+ {
545+ message : "You have triggered an abuse detection mechanism. Please wait before retrying." ,
546+ documentation_url :
547+ "https://docs.github.com/rest/overview/resources-in-the-rest-api#abuse-rate-limits" ,
548+ } ,
549+ { status : 403 , headers : { "retry-after" : "60" , "x-ratelimit-remaining" : "4878" } } ,
550+ ) ,
551+ ) ;
552+ return Effect . gen ( function * ( ) {
553+ yield * TestClock . setTime ( NOW ) ;
554+ const api = yield * GitHubRest . GitHubRest ;
555+ const read = { host : "github.com" , operation : "checks" , path : "repos/acme/web/pulls/7" } ;
556+ expect ( yield * Effect . flip ( api . rest ( read ) ) ) . toMatchObject ( {
557+ _tag : "GitHubApiRateLimitError" ,
558+ retryAt : NOW + 60_000 ,
559+ } ) ;
560+ expect ( ( yield * Effect . flip ( api . rest ( read ) ) ) . _tag ) . toBe ( "SourceControlRateLimitPausedError" ) ;
561+ expect ( requests ) . toHaveLength ( 1 ) ;
562+ } ) . pipe ( Effect . provide ( layer ) ) ;
563+ } ) ;
564+
513565 it . effect ( "drops a refused token so the next request asks the source again" , ( ) => {
514566 const { layer, requests, invalidations } = harness ( ( request ) =>
515567 request . headers . authorization === "Bearer first"
0 commit comments