aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.
Apache License 2.0
266 stars 155 forks source link

fetch with URL object fails with `Cannot read properties of undefined (reading 'has')` #648

Open borgoat opened 3 months ago

borgoat commented 3 months ago

We are using fetch passing a URL object as resource parameter - and a second options argument containing headers. The first parameter may be any object with a stringifier.^1

However, currently it implies here^2 that any object passed as first argument to fetch must be a Request.

TypeError: Cannot read properties of undefined (reading 'has')\n    at o9.fetch (/node_modules/.pnpm/aws-xray-sdk-fetch@3.6.0_aws-xray-sdk-core@3.6.0/node_modules/aws-xray-sdk-fetch/lib/fetch_p.js:71:25)\n    at o9.getData (/libs/instruments/service-cityfalcon/src/lib/cityfalcon.service.ts:179:12)\n    at params (/libs/instruments/service-cityfalcon/src/lib/cityfalcon.service.ts:60:14)\n    at Array.map (<anonymous>)\n    at o9.getMarketNewsTimeline (/libs/instruments/service-cityfalcon/src/lib/cityfalcon.service.ts:59:18)\n    at mWe (/libs/instruments/cloud/src/lib/market-news/market-news.get-market-news.fn/index.ts:103:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at gfe (/node_modules/.pnpm/@middy+core@4.7.0/node_modules/@middy/core/index.js:120:32)
rslfilho commented 1 month ago

Im having the same issue here, was using a URL object as first parameter for fetch, and encounter the same error. Not every time the first parameter is a object, it will be a Request. For now i updated my code to send the URL.href string as resource, but should be fixed