(params?: { method?: 'HEAD' | 'GET' })
| 509 | const { href: cacheKey } = new URL(dataHref, window.location.href) |
| 510 | const deploymentId = getDeploymentId() |
| 511 | const getData = (params?: { method?: 'HEAD' | 'GET' }) => |
| 512 | fetchRetry(dataHref, isServerRender ? 3 : 1, { |
| 513 | headers: Object.assign( |
| 514 | {} as HeadersInit, |
| 515 | isPrefetch ? { purpose: 'prefetch' } : {}, |
| 516 | isPrefetch && hasMiddleware ? { 'x-middleware-prefetch': '1' } : {}, |
| 517 | deploymentId ? { 'x-deployment-id': deploymentId } : {} |
| 518 | ), |
| 519 | method: params?.method ?? 'GET', |
| 520 | }) |
| 521 | .then((response) => { |
| 522 | if (response.ok && params?.method === 'HEAD') { |
| 523 | return { dataHref, response, text: '', json: {}, cacheKey } |
| 524 | } |
| 525 | |
| 526 | return response.text().then((text) => { |
| 527 | if (!response.ok) { |
| 528 | /** |
| 529 | * When the data response is a redirect because of a middleware |
| 530 | * we do not consider it an error. The headers must bring the |
| 531 | * mapped location. |
| 532 | * TODO: Change the status code in the handler. |
| 533 | */ |
| 534 | if ( |
| 535 | hasMiddleware && |
| 536 | [301, 302, 307, 308].includes(response.status) |
| 537 | ) { |
| 538 | return { dataHref, response, text, json: {}, cacheKey } |
| 539 | } |
| 540 | |
| 541 | if (response.status === 404) { |
| 542 | if (tryToParseAsJSON(text)?.notFound) { |
| 543 | return { |
| 544 | dataHref, |
| 545 | json: { notFound: SSG_DATA_NOT_FOUND }, |
| 546 | response, |
| 547 | text, |
| 548 | cacheKey, |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | const error = new Error(`Failed to load static props`) |
| 554 | |
| 555 | /** |
| 556 | * We should only trigger a server-side transition if this was |
| 557 | * caused on a client-side transition. Otherwise, we'd get into |
| 558 | * an infinite loop. |
| 559 | */ |
| 560 | if (!isServerRender) { |
| 561 | markAssetError(error) |
| 562 | } |
| 563 | |
| 564 | throw error |
| 565 | } |
| 566 | |
| 567 | let dplResponseHeader = response.headers.get( |
| 568 | NEXT_NAV_DEPLOYMENT_ID_HEADER |
no test coverage detected