Add error handling to sitemap.ts for build time
This commit is contained in:
@@ -4,7 +4,12 @@ import { getProducts } from "@/lib/woocommerce";
|
|||||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||||
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://dev.manoonoils.com";
|
const baseUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://dev.manoonoils.com";
|
||||||
|
|
||||||
const products = await getProducts();
|
let products: any[] = [];
|
||||||
|
try {
|
||||||
|
products = await getProducts();
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Failed to fetch products for sitemap during build');
|
||||||
|
}
|
||||||
|
|
||||||
const productUrls = products
|
const productUrls = products
|
||||||
.filter((p) => p.status === "publish")
|
.filter((p) => p.status === "publish")
|
||||||
|
|||||||
Reference in New Issue
Block a user