feat: improve error handling in API calls for blog, clinic, and doctor data retrieval
This commit is contained in:
+10
-12
@@ -11,16 +11,13 @@ import { imageUrl } from "@/helper";
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
const getClinic = cache(async (slug) => {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/v1/clinic/${slug}`, {
|
||||
next: { revalidate: 3600, tags: [`clinic-${slug}`] },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const json = await res.json();
|
||||
return json?.data?.data ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
const res = await fetch(`${API_URL}/api/v1/clinic/${slug}`, {
|
||||
next: { revalidate: 3600, tags: [`clinic-${slug}`] },
|
||||
});
|
||||
if (res.status === 404 || res.status === 400) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch clinic: ${res.status}`);
|
||||
const json = await res.json();
|
||||
return json?.data?.data ?? null;
|
||||
});
|
||||
|
||||
export async function generateMetadata({ params }) {
|
||||
@@ -28,9 +25,10 @@ export async function generateMetadata({ params }) {
|
||||
const { matchedCity } = await getStateInfo();
|
||||
const siteName = matchedCity?.site_name || "نوبت 724";
|
||||
|
||||
const clinic = await getClinic(slug);
|
||||
if (!clinic) notFound();
|
||||
|
||||
try {
|
||||
const clinic = await getClinic(slug);
|
||||
if (!clinic) return {};
|
||||
|
||||
const title = `${clinic.title} | ${siteName}`;
|
||||
const description = `رزرو نوبت و اطلاعات ${clinic.title}. مشاهده لیست پزشکان و خدمات درمانی موجود.`;
|
||||
|
||||
Reference in New Issue
Block a user