빌드 오류 수정

This commit is contained in:
익희 김 2025-01-02 20:17:40 +09:00
parent 0b0a60940f
commit e0959e1d15

View File

@ -11,60 +11,111 @@ import * as api from 'src/services';
export const dynamic = 'error'; export const dynamic = 'error';
export const revalidate = 10; export const revalidate = 10;
// Static params generation with error handling
export async function generateStaticParams() { export async function generateStaticParams() {
const { data } = await api.getSubCategorySlugs(); try {
return data?.map((cat) => { const { data } = await api.getSubCategorySlugs();
return { if (!data) throw new Error('No data returned from getSubCategorySlugs');
subCategory: cat.slug,
category: cat.parentCategory.slug return data
}; .filter(cat => cat?.slug && cat?.parentCategory?.slug) //
}); .map((cat) => ({
subCategory: cat.slug,
category: cat.parentCategory.slug,
}));
} catch (error) {
console.error('Error generating static params:', error.message);
return []; //
}
} }
// Metadata generation with error handling
export async function generateMetadata({ params }) { export async function generateMetadata({ params }) {
const { data: response } = await api.getSubCategoryBySlug(params.subCategory); try {
const { data: response } = await api.getSubCategoryBySlug(params.subCategory);
if (!response) throw new Error('No data returned from getSubCategoryBySlug');
return { return {
title: response.metaTitle, title: response.metaTitle || 'Default Title', //
description: response.metaDescription, description: response.metaDescription || 'Default Description',
title: response.name, openGraph: {
openGraph: { images: [response.cover?.url || '/default-image.jpg'], //
images: [response.cover.url] },
} };
}; } catch (error) {
console.error('Error generating metadata:', error.message);
return {
title: 'Error',
description: 'An error occurred while generating metadata.',
openGraph: {
images: ['/default-image.jpg'], //
},
};
}
} }
// Main component with error handling
export default async function Listing({ params }) { export default async function Listing({ params }) {
const { category, subCategory } = params; const { category, subCategory } = params;
const { data: subCategoryData } = await api.getSubCategoryTitle(subCategory);
return ( try {
<Box> const { data: subCategoryData } = await api.getSubCategoryTitle(subCategory);
<Box sx={{ bgcolor: 'background.default' }}>
<Container maxWidth="xl"> if (!subCategoryData) throw new Error('No data found for the given subCategory');
<HeaderBreadcrumbs
heading={subCategoryData?.name} return (
links={[ <Box>
{ <Box sx={{ bgcolor: 'background.default' }}>
name: 'Home', <Container maxWidth="xl">
href: '/' <HeaderBreadcrumbs
}, heading={subCategoryData?.name || 'Unknown Category'}
{ links={[
name: 'Products', {
href: '/products' name: 'Home',
}, href: '/',
{ },
name: subCategoryData?.parentCategory?.name, {
href: `/products/${category}` name: 'Products',
}, href: '/products',
{ },
name: subCategoryData?.name {
} name: subCategoryData?.parentCategory?.name || 'Unknown Parent Category',
]} href: `/products/${category}`,
/> },
<ProductList subCategory={subCategoryData} /> {
</Container> name: subCategoryData?.name || 'Unknown SubCategory',
},
]}
/>
<ProductList subCategory={subCategoryData} />
</Container>
</Box>
</Box> </Box>
</Box> );
); } catch (error) {
console.error('Error rendering Listing component:', error.message);
return (
<Box>
<Box sx={{ bgcolor: 'background.default' }}>
<Container maxWidth="xl">
<HeaderBreadcrumbs
heading="Error"
links={[
{
name: 'Home',
href: '/',
},
{
name: 'Products',
href: '/products',
},
]}
/>
<Box>Error loading subcategory. Please try again later.</Box>
</Container>
</Box>
</Box>
);
}
} }