open-sauced / app

🍕 Insights into your entire open source ecosystem.
https://pizza.new
Apache License 2.0
430 stars 230 forks source link

Bug: User profile 404ing when in fact it was a server error #4042

Closed nickytonline closed 3 months ago

nickytonline commented 3 months ago

This is just a hypothesis, but my user profile in prod was 404ing for about a good 5-6 minutes and finally displayed.

The current code looks like this in getServerSideProps for the user profile page. We should check if the request to the API succeeded (even if a 404) or if it failed.

export const getServerSideProps = async (context: UserSSRPropsContext) => {
  const { username } = context.params ?? { username: "" };

  if (!isValidUrlSlug(username)) {
    return { notFound: true };
  }

  const req = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/users/${username}`, {
    headers: {
      accept: "application/json",
    },
  });

  if (!req.ok) {
-    return { notFound: true };
+    if (req.status === 404) {
+      return {
+        notFound: true,
+      };
+    }
+
+    const errorText = `Failed to load user profile: ${username}`;
+    captureException(new Error(errorText, { cause: req.statusText }));
+    throw new Error(errorText);
  }

  const userData = (await req.json()) as DbUser;
  const ogImage = siteUrl(`og-images/dev-card`, { username });

  // Cache page for 60 seconds
  context.res.setHeader("Cache-Control", "public, max-age=0, must-revalidate");
  context.res.setHeader("Netlify-CDN-Cache-Control", "public, max-age=0, stale-while-revalidate=60");
  context.res.setHeader("Cache-Tag", `user-profiles,user-profile-${username}`);

  return {
    props: { username, user: userData, ogImage },
  };
};
github-actions[bot] commented 3 months ago

Thanks for the issue, our team will look into it as soon as possible! If you would like to work on this issue, please wait for us to decide if it's ready. The issue will be ready to work on once we remove the "needs triage" label.

To claim an issue that does not have the "needs triage" label, please leave a comment that says ".take". If you have any questions, please comment on this issue.

For full info on how to contribute, please check out our contributors guide.

open-sauced[bot] commented 3 months ago

:tada: This issue has been resolved in version 2.61.0-beta.6 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

open-sauced[bot] commented 3 months ago

:tada: This issue has been resolved in version 2.61.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: