@@ -21,7 +21,7 @@ import * as Path from "effect/Path";
2121import * as PlatformError from "effect/PlatformError" ;
2222import * as Schema from "effect/Schema" ;
2323import * as TestClock from "effect/testing/TestClock" ;
24- import { HttpClient , HttpClientResponse , HttpServerResponse } from "effect/http" ;
24+ import { HttpClient , HttpClientError , HttpClientResponse , HttpServerResponse } from "effect/http" ;
2525import { vi } from "vite-plus/test" ;
2626
2727import * as ServerSecretStore from "../auth/ServerSecretStore.ts" ;
@@ -235,7 +235,8 @@ describe("AssetAccess", () => {
235235 } ;
236236 const serve = (
237237 token : string | null ,
238- respond : ( url : string ) => Response ,
238+ /** `null` stands for a host the server cannot reach. */
239+ respond : ( url : string ) => Response | null ,
239240 invalidated : Array < string > = [ ] ,
240241 ) => {
241242 const requests : Array < { url : string ; authorization : string | undefined } > = [ ] ;
@@ -250,7 +251,14 @@ describe("AssetAccess", () => {
250251 HttpClient . HttpClient ,
251252 HttpClient . make ( ( request ) => {
252253 requests . push ( { url : request . url , authorization : request . headers . authorization } ) ;
253- return Effect . succeed ( HttpClientResponse . fromWeb ( request , respond ( request . url ) ) ) ;
254+ const answer = respond ( request . url ) ;
255+ return answer === null
256+ ? Effect . fail (
257+ new HttpClientError . HttpClientError ( {
258+ reason : new HttpClientError . TransportError ( { request } ) ,
259+ } ) ,
260+ )
261+ : Effect . succeed ( HttpClientResponse . fromWeb ( request , answer ) ) ;
254262 } ) ,
255263 ) ,
256264 Effect . scoped ,
@@ -313,6 +321,12 @@ describe("AssetAccess", () => {
313321 const refused = serve ( "expired" , ( ) => new Response ( null , { status : 401 } ) , invalidated ) ;
314322 expect ( ( yield * refused . response ) . headers . location ) . toBe ( asset . url ) ;
315323 expect ( invalidated ) . toEqual ( [ "gitlab.example.com" ] ) ;
324+
325+ // A server that cannot reach GitLab leaves the browser to try, as it did before.
326+ const unreachable = serve ( "glab-token" , ( ) => null ) ;
327+ expect ( ( yield * unreachable . response ) . headers . location ) . toBe ( asset . url ) ;
328+ const failing = serve ( "glab-token" , ( ) => new Response ( null , { status : 503 } ) ) ;
329+ expect ( ( yield * failing . response ) . headers . location ) . toBe ( asset . url ) ;
316330 } ) ,
317331 ) ;
318332
0 commit comments