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 stack not exposed when axios error occurs inside `getInitialProps` function

See original GitHub issue

Bug report

Error stack not exposed when axios error occurs inside getInitialProps function

Describe the bug

In the getInitialProps function, the error page is not displayed properly in client side rendering when an error occurs due to axios.

Page code

// pages/example.js
...
ExamplePage.getInitialProps = () => {
  // The code below throws a CORS error on the client side.
  await axios.get('https://google.com');
  ...
  return {}
}
...

Run script

// Run nextjs in development mode.
$ next dev

Expected behavior

If an error occurs in getInitialProps function when entering a page through next/route(route.push) on the client side, the error information should be exposed on the page, but if an axios error occurs, the error page is not exposed(As a result of testing, other errors except axios error are normally showing error information on the page.).

System information

  • Browser Chrome
  • Version of Next.js: 9.2.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rafaelalmeidatkcommented, Feb 22, 2020

This is a known problem with axios because it rewrites the stack trace. I wrote about a workaround here: https://github.com/rafaelalmeidatk/TIL/issues/4

0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

getInitialProps in Next.js does not get data from server
I have solved the issue. It occurred because I broke a simple rule. According to next.js document, there is a note saying.
Read more >
Fetching and hydrating a Next.JS app using ... - Medium
When your app needs to process data from an external source (as in a fetch for a remote JSON file) you have two...
Read more >
axioserror: connect econnrefused 127.0.0.1:8080 - You.com
This error originated either by throwing inside of an async fun ction without a catch block, or by rejecting a promise which was...
Read more >
Advanced Features: Error Handling - Next.js
Handling Errors in Development ... When there is a runtime error during the development phase of your Next.js application, you will encounter an...
Read more >
[Solved]-images is not rendering on webpage while mapping ...
Coding example for the question images is not rendering on webpage while mapping the image from data.js file in react js-Reactjs.
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