Handle fetch error in page server component
Answered
MarkMiklos posted this in #help-forum
How should I approach this if i would like to do the following commented on the photo?
What is the best way, or is it even okay to do what i would like to do here?
What is the best way, or is it even okay to do what i would like to do here?
Answered by B33fb0n3
you can return the specific part as html (as the server need to compile everything).
So either add html to your actual page (like an alert) or replace the whole html with your specific error (like a custom error page for only this error)
So either add html to your actual page (like an alert) or replace the whole html with your specific error (like a custom error page for only this error)
5 Replies
@MarkMiklos How should I approach this if i would like to do the following commented on the photo?
What is the best way, or is it even okay to do what i would like to do here?
you can return the specific part as html (as the server need to compile everything).
So either add html to your actual page (like an alert) or replace the whole html with your specific error (like a custom error page for only this error)
So either add html to your actual page (like an alert) or replace the whole html with your specific error (like a custom error page for only this error)
Answer
@B33fb0n3 you can return the specific part as html (as the server need to compile everything).
So either *add* html to your actual page (like an alert) or *replace* the whole html with your specific error (like a custom error page for only this error)
export default async function Page({ params }: { params: { slug: string } }) {
const { slug } = await params;
const data = await getCompanyData(slug);
if (data.response !== 'OK') {
return <CustomErrorModal />
}
return (
<main className="container mx-auto min-h-screen">
PAGE
</main>
);
}So just like that?
Make sense 😅 thanks
happy to help