Added Recipe errorComponent.

This commit is contained in:
Jesse Brault 2024-07-31 17:43:46 -05:00
parent 8a5fd0a466
commit 68702595c5

View File

@ -1,8 +1,10 @@
import {
createFileRoute,
ErrorComponent,
useLoaderData,
useParams
} from '@tanstack/react-router'
import { ApiError } from '../../api/ApiError'
import getRecipe from '../../api/getRecipe'
import Recipe from '../../pages/recipe/Recipe'
@ -24,6 +26,16 @@ export const Route = createFileRoute('/recipes/$username/$slug')({
})
return <Recipe {...{ recipe }} />
},
errorComponent({ error }) {
if (error instanceof ApiError) {
return (
<p>
{error.status}: {error.message}
</p>
)
}
return <ErrorComponent error={error} />
},
notFoundComponent() {
const { username, slug } = useParams({
from: '/recipes/$username/$slug'