@@ -3,7 +3,7 @@ import LRU from 'tiny-lru';
33import { Logger } from '@graphql-hive/logger' ;
44import CircuitBreaker from '../circuit-breaker/circuit.js' ;
55import { defaultCircuitBreakerConfiguration } from './circuit-breaker.js' ;
6- import { http } from './http-client.js' ;
6+ import { http , HttpCallConfig } from './http-client.js' ;
77import type { PersistedDocumentsConfiguration } from './types' ;
88
99type HeadersObject = {
@@ -24,6 +24,8 @@ export function createPersistedDocuments(
2424 config : PersistedDocumentsConfiguration & {
2525 logger : Logger ;
2626 fetch ?: typeof fetch ;
27+ retry ?: HttpCallConfig [ 'retry' ] ;
28+ timeout ?: HttpCallConfig [ 'retry' ] ;
2729 } ,
2830) : PersistedDocuments {
2931 const persistedDocumentsCache = LRU < string > ( config . cache ?? 10_000 ) ;
@@ -60,6 +62,7 @@ export function createPersistedDocuments(
6062 isRequestOk,
6163 fetchImplementation : config . fetch ,
6264 signal,
65+ retry : config . retry ,
6366 } )
6467 . then ( async response => {
6568 if ( response . status !== 200 ) {
@@ -95,14 +98,20 @@ export function createPersistedDocuments(
9598 . then ( async ( ) => {
9699 const cdnDocumentId = documentId . replaceAll ( '~' , '/' ) ;
97100
101+ let lastError : unknown = null ;
102+
98103 for ( const breaker of circuitBreakers ) {
99104 try {
100105 return await breaker . fire ( cdnDocumentId ) ;
101106 } catch ( error : unknown ) {
102107 config . logger . debug ( { error } ) ;
108+ lastError = error ;
103109 }
104110 }
105- throw new Error ( 'Failed to look up artifact.' ) ;
111+ if ( lastError ) {
112+ config . logger . error ( { error : lastError } ) ;
113+ }
114+ throw new Error ( 'Failed to look up persisted operation.' ) ;
106115 } )
107116 . then ( result => {
108117 persistedDocumentsCache . set ( documentId , result ) ;
0 commit comments