Worker returning HTTP 429

I have created a worker that acts like a proxy.
Scenario:

  1. User hits URL “X”
  2. It gets routed to worker A.
  3. Worker A internally makes a request to URL Y
  4. Replies Response return from step(3) to client
  5. I am logging both success and error if the worker hits during step(3)

My performance test hits at a rate of 100-200 request per second.
Issue: I am receiving HTTP 429 after a certain rate of invocation, however Logging is not capturing the response.
I clearly see that Domain “Y” is returning 429 but want to understand if the worker is executed if there is a HTTP 429.

Worker Script:
addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})

/**

  • Respond to the request
  • @param {Request} request
    */
    async function handleRequest(request) {
    let originalResponse;
    try{

let expResponse= await findVariant(request);
let exp = await expResponse.text();
let retResponse= new Response(exp, {status: expResponse.status,headers:{“Content-Type”:“application/json; charset=utf-8”}})
await postMessage(retResponse,exp,“success”)
return retResponse;
}catch(err){
const stack = JSON.stringify(err.stack) || err
let response1 = new Response(stack, originalResponse)=
response1.headers.set(‘X-Debug-stack’, stack)
response1.headers.set(‘X-Debug-err’, err)
await postMessage(response1,stack,“error”);
return response1;
}
}

function findVariant(request){

let newRequestInit = {
method: ‘POST’,=
redirect: ‘follow’,
cf: { apps: false }
}
let url = “”
url = new URL(url)
url.hostname = “”
const newRequest = new Request(url, new Request(request, newRequestInit))
try {
return fetch(newRequest);
} catch (e) {
return new Response(JSON.stringify({ error: e.message }), { status: 500 })
}
}

function postMessage(responseLog,data,frm){
let postObj = {“data”:data,“httpStatus”:responseLog.status,“type”:frm};
for (var pair of responseLog.headers.entries()) {
postObj[pair[0]]=pair[1]
}
let log = JSON.stringify(postObj);

let newRequestInit = {
method: ‘POST’,
redirect: ‘follow’,
cf: { apps: false },
body:log
}
let url = “”
url = new URL(url)
url.hostname = “”
const newRequest = new Request(url, newRequestInit)
try {
return fetch(newRequest);
} catch (e) {
//return new Response(JSON.stringify({ error: e.message }), { status: 500 })
}
}

Any help in identifying where exactly the relay of HTTP 429 is happening.
Appreciate your help and thanks a ton in advance.

Thanks
Shiv