Error on first load getInitialProps
See original GitHub issueDescribe 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
- Refresh the browser or open URL directly (https://d3ejqmemi47nwv.cloudfront.net/)
- 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:
- Created 3 years ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, I’ll have a look later this weekend.
@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