#Custom Error Page isn't working

17 messages · Page 1 of 1 (latest)

plush siren
#

How can I make dynamic custom error page? I have made like this but it doesn't seem to work. Because the error screen is still using the default.

// app/error.tsx
"use client"; // Required for error.js to work
// @ts-nocheck
import { useEffect } from "react";

export default function Error({ error, reset }) {
  // Log the error to an error reporting service if needed
  useEffect(() => {
    console.error("Error caught:", error);
  }, [error]);

  // Render a dynamic error page
  return (
    <html lang="en">
      <body>
        <div style={{ padding: "2rem", textAlign: "center" }}>
          <h1>Oops! Something went wrong.</h1>

          {/* Dynamically show the error message */}
          <p>{error?.message || "An unknown error occurred."}</p>

          {/* Provide an action to retry */}
          <button
            onClick={() => {
              // Attempt to recover by resetting the error boundary
              reset();
            }}
            style={{
              marginTop: "1rem",
              padding: "0.5rem 1rem",
              background: "#0070f3",
              color: "#fff",
              border: "none",
              borderRadius: "4px",
              cursor: "pointer",
            }}
          >
            Try Again
          </button>
        </div>
      </body>
    </html>
  );
}
rugged gyroBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

plush siren
#

Up

dusk elk
#

Of it’s just error boundary around your page (error.tsx) it shouldn’t render <html> and <body>

plush siren
#

Then how can I make sure the display.

dusk elk
#

Build your app and try it:
“npm run build”
“npm run start”

#

This is the production version of your app even if it’s not deployed to a production server

plush siren
#

The display is still using the default from nextjs

dusk elk
#

Oh but you want the “not-found.tsx” file not the error.tsx or global-error.tsx

plush siren
#

Because what I want to achieve is just make one error page handling to cover all errors.

dusk elk
#

Not sure about that honestly 😅

plush siren
#

But it means that usually to deal with it, we make the not-found file and other error files separately?