@@ -33,52 +33,31 @@ interface LoggerIncomingHttpHeaders extends IncomingHttpHeaders {
3333
3434app . use ( requestLoggingMiddleware ( ) ) ;
3535
36- // Function to retry fetch requests with exponential backoff .
37- const retryFetch = async (
36+ // Function to make authenticated fetch requests.
37+ const authenticatedFetch = async (
3838 url : URL ,
3939 options : RequestInit ,
4040 isIamEnabled : boolean ,
4141 region : string | undefined ,
42- serviceType : string ,
43- retryDelay = 10000 ,
44- refetchMaxRetries = 1
42+ serviceType : string
4543) => {
46- for ( let i = 0 ; i < refetchMaxRetries ; i ++ ) {
47- const iamOptions = isIamEnabled
48- ? {
49- service : serviceType ,
50- region : region ,
51- }
52- : undefined ;
53- const request : RequestInit = {
54- ...options ,
55- compress : false , // prevent automatic decompression
56- } ;
57- const signedRequest = await signRequest ( url , request , iamOptions ) ;
58-
59- try {
60- const res = await fetch ( url , signedRequest ) ;
61- if ( ! res . ok ) {
62- proxyLogger . error ( "!!Request failure!!" ) ;
63- return res ;
64- } else {
65- return res ;
44+ const iamOptions = isIamEnabled
45+ ? {
46+ service : serviceType ,
47+ region : region ,
6648 }
67- } catch ( err ) {
68- if ( refetchMaxRetries === 1 ) {
69- // Don't log about retries if retrying is not used
70- throw err ;
71- } else if ( i === refetchMaxRetries - 1 ) {
72- proxyLogger . error ( err , "!!Proxy Retry Fetch Reached Maximum Tries!!" ) ;
73- throw err ;
74- } else {
75- proxyLogger . debug ( "Proxy Retry Fetch Count::: " + i ) ;
76- await new Promise ( resolve => setTimeout ( resolve , retryDelay ) ) ;
77- }
78- }
49+ : undefined ;
50+ const request : RequestInit = {
51+ ...options ,
52+ compress : false , // prevent automatic decompression
53+ } ;
54+ const signedRequest = await signRequest ( url , request , iamOptions ) ;
55+
56+ const res = await fetch ( url , signedRequest ) ;
57+ if ( ! res . ok ) {
58+ proxyLogger . error ( "!!Request failure!!" ) ;
7959 }
80- // Should never reach this code
81- throw new Error ( "retryFetch failed to complete retry logic" ) ;
60+ return res ;
8261} ;
8362
8463// Function to fetch data from the given URL and send it as a response.
@@ -92,7 +71,7 @@ async function fetchData(
9271 serviceType : string
9372) {
9473 try {
95- const response = await retryFetch (
74+ const response = await authenticatedFetch (
9675 new URL ( url ) ,
9776 options ,
9877 isIamEnabled ,
@@ -174,7 +153,7 @@ app.post("/sparql", async (req, res, next) => {
174153 }
175154 proxyLogger . debug ( `Cancelling request ${ queryId } ...` ) ;
176155 try {
177- await retryFetch (
156+ await authenticatedFetch (
178157 new URL ( `${ graphDbConnectionUrl } /sparql/status` ) ,
179158 {
180159 method : "POST" ,
@@ -279,7 +258,7 @@ app.post("/gremlin", async (req, res, next) => {
279258 }
280259 proxyLogger . debug ( `Cancelling request ${ queryId } ...` ) ;
281260 try {
282- await retryFetch (
261+ await authenticatedFetch (
283262 new URL (
284263 `${ graphDbConnectionUrl } /gremlin/status?cancelQuery&queryId=${ encodeURIComponent ( queryId ) } `
285264 ) ,
0 commit comments