change fetch to axios
This commit is contained in:
@@ -1,23 +1,28 @@
|
||||
import { API_BASE_URL } from "@/config/const";
|
||||
import { AboutResponse, Restaurant } from "../(Main)/about/types/Types";
|
||||
import axios from "axios";
|
||||
|
||||
export async function getRestaurant(slug: string): Promise<Restaurant> {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/public/restaurants/${slug}`, {
|
||||
cache: "no-store",
|
||||
const response = await axios(`${API_BASE_URL}/public/restaurants/${slug}`, {
|
||||
// cache: "no-store",
|
||||
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-SLUG": slug,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.log("response", response);
|
||||
|
||||
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.json();
|
||||
const data: AboutResponse = await response.data;
|
||||
|
||||
if (!data.success || !data.data) {
|
||||
throw new Error("RESTAURANT_NOT_FOUND");
|
||||
@@ -25,6 +30,8 @@ export async function getRestaurant(slug: string): Promise<Restaurant> {
|
||||
|
||||
return data.data;
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
|
||||
if (error instanceof Error && error.message === "RESTAURANT_NOT_FOUND") {
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user