fe-middleware/src/services/botApiService.ts

19 lines
572 B
TypeScript

import { env } from "bun";
import logger from "src/logger";
import { BotApiResponse } from "src/types/BotApiResponse";
const BOT_API_URI = env.BOT_API_URI;
export async function getAll(): Promise<BotApiResponse> {
const get_url = `${BOT_API_URI}/images`;
const response: BotApiResponse = (await fetch(get_url).then(async (res) => {
if (!res.ok) {
logger.error(`${res.status}: ${res.statusText}, ${await res.text()}`);
throw new Error("Error fetching images");
} else {
return res.json();
}
})) as BotApiResponse;
return response;
}