ISR Test #2

Fetches a random number from an API. If it's < 5, throws an error. Revalidates every 2 seconds.

Note that errors are ignored during build phase.

Num

8

Code

export async function getStaticProps() {
  const res = await fetch('https://random-data-api.com/api/number/random_number');
  const data = await res.json();
  const num = data.digit;

  console.log('isr-2 getStaticProps running, num:', num);

  if (!isBuilding() && num < 5) throw new Error('isr-2 Failed to get static props');

  return {
    props: {
      num,
    },
    revalidate: 2,
  }
}

Local production build:

Shows the console message as outlined in the code. Logs the error when there is an error.

Vercel deployments:

Console seems erratic… can't seem to match the logs with what's showing up in the app. getStaticProps also seems to execute multiple times per page refresh…