fetch with URL object fails with `Cannot read properties of undefined (reading 'has')`
- Dominant language
- JavaScript
- Stars
- 280
- Forks
- 157
- PR merge metrics
- No merged PRs in 30d
Description
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 ()\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)
```
[^1]: https://developer.mozilla.org/en-US/docs/Web/API/fetch
[^2]: https://github.com/aws/aws-xray-sdk-node/blob/58dd586b2e1de562dce07c74e0d066d2b74ad210/sdk_contrib/fetch/lib/fetch_p.js#L63C11-L65
Contributor guide
Research direction
Start in sdk_contrib/fetch/lib/fetch_p.js around the logic referenced in the issue, then compare it with the Fetch API behavior for a URL object and a second options argument containing headers. Reproduce the reported call and confirm that URL objects with headers no longer trigger the undefined-property error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100