This commit is contained in:
@@ -3,23 +3,22 @@ import { API_BASE_URL } from "@/config/const";
|
||||
import { AboutResponse, Restaurant } from "../(Main)/about/types/Types";
|
||||
import axios from "axios";
|
||||
|
||||
export const RESTAURANT_FETCH_TIMEOUT_MS = 10_000;
|
||||
|
||||
async function fetchRestaurant(slug: string): Promise<Restaurant> {
|
||||
try {
|
||||
const response = await axios(`${API_BASE_URL}/public/restaurants/${slug}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-SLUG": slug,
|
||||
const response = await axios.get<AboutResponse>(
|
||||
`${API_BASE_URL}/public/restaurants/${slug}`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-SLUG": slug,
|
||||
},
|
||||
timeout: RESTAURANT_FETCH_TIMEOUT_MS,
|
||||
},
|
||||
});
|
||||
);
|
||||
|
||||
if (!response.data) {
|
||||
if (response.status === 404) {
|
||||
throw new Error("RESTAURANT_NOT_FOUND");
|
||||
}
|
||||
throw new Error(`Failed to fetch restaurant: ${response.status}`);
|
||||
}
|
||||
|
||||
const data: AboutResponse = await response.data;
|
||||
const data = response.data;
|
||||
|
||||
if (!data.success || !data.data) {
|
||||
throw new Error("RESTAURANT_NOT_FOUND");
|
||||
@@ -30,6 +29,9 @@ async function fetchRestaurant(slug: string): Promise<Restaurant> {
|
||||
if (error instanceof Error && error.message === "RESTAURANT_NOT_FOUND") {
|
||||
throw error;
|
||||
}
|
||||
if (axios.isAxiosError(error) && error.response?.status === 404) {
|
||||
throw new Error("RESTAURANT_NOT_FOUND");
|
||||
}
|
||||
throw new Error(`Failed to fetch restaurant data: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user