fe-middleware/src/services/BotApiService.ts

24 lines
751 B
TypeScript
Raw Normal View History

import { env } from "bun";
import logger from "src/logger";
import { BotApiResponse } from "src/types/BotApiResponse";
2024-03-28 11:43:24 +00:00
class BotApiService {
readonly BOT_API_URI = env.BOT_API_URI;
2024-03-28 11:43:24 +00:00
async getAll(): Promise<BotApiResponse> {
const get_url = `${this.BOT_API_URI}/images`;
2024-03-28 11:43:24 +00:00
const response: BotApiResponse = await fetch(get_url)
.then(async res => {
2024-03-28 11:43:24 +00:00
if (!res.ok) {
logger.error(`${res.status}: ${res.statusText}, ${await res.text()}`)
2024-03-28 11:43:24 +00:00
throw new Error("Error fetching images");
} else {
return res.json();
2024-03-28 11:43:24 +00:00
}
}) as BotApiResponse;
return response;
}
}
export default new BotApiService();