async fetch(request: Request, env: Env): Promise<Response> {
// note: "getRandom" to be replaced with latency-aware routing in the near future
try {
const instanceNumber = env.WORKER_ENV === 'production' ? 2 : 1;
const containerInstance = await getRandom(
env.API_CONTAINER,
instanceNumber,
);
const rs = await containerInstance.fetch(request);
return rs;
} catch (error) {
// Surface failures cleanly in Cloudflare's logs before bubbling up
console.error('[CloudflareContainer] fetch failed', {
url: request.url,
method: request.method,
message: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined,
});
throw error instanceof Error ? error : new Error(String(error));
}
},
async fetch(request: Request, env: Env): Promise<Response> {
// note: "getRandom" to be replaced with latency-aware routing in the near future
try {
const instanceNumber = env.WORKER_ENV === 'production' ? 2 : 1;
const containerInstance = await getRandom(
env.API_CONTAINER,
instanceNumber,
);
const rs = await containerInstance.fetch(request);
return rs;
} catch (error) {
// Surface failures cleanly in Cloudflare's logs before bubbling up
console.error('[CloudflareContainer] fetch failed', {
url: request.url,
method: request.method,
message: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined,
});
throw error instanceof Error ? error : new Error(String(error));
}
},