question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on first load getInitialProps

See original GitHub issue

Describe the bug The initial request to the API on page load shows an error, but navigating back to the page (using nextjs Link) makes the request work again, only the first-page load API request fails

To Reproduce Steps to reproduce the behavior: See the video attached: https://www.youtube.com/watch?v=63FDXwlIuEA

  1. Refresh the browser or open URL directly (https://d3ejqmemi47nwv.cloudfront.net/)
  2. Error appears on the screen

Additional context Minimal repository to reproduce the error https://github.com/juancjara/servlerss-next-error serverless.yml

testApp:
  component: "@sls-next/serverless-component@1.15.1"

Error on first load

{
    "message": "Request failed with status code 403",
    "name": "Error",
    "stack": "Error: Request failed with status code 403\n    at createError (/var/task/pages/index.js:3471:15)\n    at settle (/var/task/pages/index.js:4435:12)\n    at IncomingMessage.handleStreamEnd (/var/task/pages/index.js:9971:11)\n    at IncomingMessage.emit (events.js:327:22)\n    at endReadableNT (_stream_readable.js:1220:12)\n    at processTicksAndRejections (internal/process/task_queues.js:84:21)",
    "config": {
      "url": "https://v8ohknm-d01mhf.s3.amazonaws.com/api/hello",
      "method": "get",
      "headers": {
        "Accept": "application/json, text/plain, */*",
        "User-Agent": "axios/0.20.0"
      },
      "transformRequest": [
        null
      ],
      "transformResponse": [
        null
      ],
      "timeout": 0,
      "xsrfCookieName": "XSRF-TOKEN",
      "xsrfHeaderName": "X-XSRF-TOKEN",
      "maxContentLength": -1,
      "maxBodyLength": -1
    }
  }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
dphangcommented, Sep 27, 2020

Thanks, I’ll have a look later this weekend.

0reactions
juancjaracommented, Sep 29, 2020

@dphang thanks so much for your help, and for this awesome library, your suggestion worked 🍾

will leave my serverless config here, if someone finds it useful

appCloudfront:
  component: "@sls-next/serverless-component@1.17.0"
  inputs:
    cloudfront:
      defaults:
        forward:
          headers:
            [
              CloudFront-Is-Desktop-Viewer,
              CloudFront-Is-Mobile-Viewer,
              CloudFront-Is-Tablet-Viewer,
              Host
            ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.JS: How to handle error in getInitialProps? - Stack Overflow
I want to fetch data from an API, and if it fails I want it to render the _error.js page. My request depends...
Read more >
getInitialProps - Data Fetching - Next.js
For the initial page load, getInitialProps will run on the server only. getInitialProps will then run on the client when navigating to a...
Read more >
How to solve Next.js window is not defined
Solve a the common ReferenceError: next.js window is not defined error that you may see when doing SSR & pre-rendering.
Read more >
Testing and error handling patterns in Next.js - LogRocket Blog
Check out these different ways to run tests and handle errors in Next.js ... First, you need to create a basic application with...
Read more >
Fetching and hydrating a Next.JS app using ... - Medium
You may be inclined to try `getInitialProps`, and it would ... Notice the `/users` row: 382 bytes in size and the first load...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found