When fetching data inside of a Server Component, you can use the response to conditionally render an error message or redirect.
export default async function Page() {
const res = await fetch(`https://...`)
const data = await res.json()
if (!res.ok) {
return 'There was an error.'
}
return '...'
}
Top comments (0)