MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / parseFetchArgs

Function parseFetchArgs

packages/core/src/instrument/fetch.ts:256–280  ·  view source on GitHub ↗
(fetchArgs: unknown[])

Source from the content-addressed store, hash-verified

254 * Exported for tests only.
255 */
256export function parseFetchArgs(fetchArgs: unknown[]): { method: string; url: string } {
257 if (fetchArgs.length === 0) {
258 return { method: 'GET', url: '' };
259 }
260
261 if (fetchArgs.length === 2) {
262 const [resource, options] = fetchArgs as [FetchResource, object];
263
264 return {
265 url: getUrlFromResource(resource),
266 method: hasProp(options, 'method')
267 ? String(options.method).toUpperCase()
268 : // Request object as first argument
269 isRequest(resource) && hasProp(resource, 'method')
270 ? String(resource.method).toUpperCase()
271 : 'GET',
272 };
273 }
274
275 const arg = fetchArgs[0];
276 return {
277 url: getUrlFromResource(arg as FetchResource),
278 method: hasProp(arg, 'method') ? String(arg.method).toUpperCase() : 'GET',
279 };
280}
281
282function getHeadersFromFetchArgs(fetchArgs: unknown[]): WebFetchHeaders | undefined {
283 const [requestArgument, optionsArgument] = fetchArgs;

Callers 2

fetch.test.tsFile · 0.90
instrumentFetchFunction · 0.85

Calls 3

isRequestFunction · 0.90
getUrlFromResourceFunction · 0.85
hasPropFunction · 0.85

Tested by

no test coverage detected