Skip to content

Commit

Permalink
add try catch (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanSmiths committed Feb 5, 2025
1 parent a2c4557 commit 48a222f
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions app/crafts/photos/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Metadata } from "next";
import { FC } from "react";
import { FC, ReactNode } from "react";
import { getPhotos } from "../../../utils/fetch/getImages";
import { photoHeaderProps } from "../../components/crafts/headerProps";
import { photosMetadata } from "../../../utils/metadata/craftsMetadata";
Expand All @@ -12,26 +12,36 @@ import Footer from "../../components/global/Footer/Footer";

export const metadata: Metadata = photosMetadata;

const Photos: FC = async () => {
const images = await getPhotos();
type PhotosLayoutProps = {
children?: ReactNode;
};

return (
<>
<Header
h1={photoHeaderProps.h1}
h2={photoHeaderProps.h2}
paragraph={photoHeaderProps.paragraph}
/>
<Navbar position={Position.Fixed} />
<Filter currentPage={Label.Photos} />
<Images images={images} />
<Footer />
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(photosSchema) }}
/>
</>
);
const PhotosLayout: FC<PhotosLayoutProps> = ({ children }) => (
<>
<Header
h1={photoHeaderProps.h1}
h2={photoHeaderProps.h2}
paragraph={photoHeaderProps.paragraph}
/>
<Navbar position={Position.Fixed} />
<Filter currentPage={Label.Photos} />
{children}
<Footer />
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(photosSchema) }}
/>
</>
);

const Photos: FC = async () => {
try {
const images = await getPhotos();
return <PhotosLayout>{images && <Images images={images} />}</PhotosLayout>;
} catch (error) {
console.error("Failed to fetch photos from database.");
return <PhotosLayout />;
}
};

export default Photos;

0 comments on commit 48a222f

Please sign in to comment.