Next.js Discord

Discord Forum

Error code in the file error.tsx

Answered
Korean bullhead posted this in #help-forum
Open in Discord
Korean bullheadOP
I need to output the content with the request error code when an error arrives. Can I somehow inside the error.tsx file handle the error code that comes when using fetch? Or maybe there is a way to call ErrorBoundary inside the page.tsx file and pass it a custom Error component? My error.tsx file looks something like this:
"use client";

import { Error } from './Error';

export default function ErrorPage (props) {
    return (
        <Error errorType={statusCode} />
    );
};


Inside the Error component, a switch/case is used to display the content depending on the error code.
Answered by Ray
error.tsx is for handling unexpected error
in your case, I think its better to create a component for that
View full answer

2 Replies