diff --git a/src/index.ts b/src/index.ts index 3d1aed8..9fe214d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { fillPeriod } from "./modules/scheduling/helpers/fillPeriod" import { createSchedule } from "./modules/scheduling/helpers/createSchedule" import { getDateRange } from "./args" import { log } from "./log" +import { exit } from "process" const main = async () => { try { @@ -35,7 +36,7 @@ const main = async () => { log.info(result) } catch (error: any) { log.error(error.message) - throw error + exit(1) } } diff --git a/src/modules/scheduling/helpers/createSchedule.ts b/src/modules/scheduling/helpers/createSchedule.ts index 083433d..8c7aa9d 100644 --- a/src/modules/scheduling/helpers/createSchedule.ts +++ b/src/modules/scheduling/helpers/createSchedule.ts @@ -1,5 +1,7 @@ +import { log } from "../../../log" import { api } from "../../core/api" import { ScheduleEntry } from "../types" +import { AxiosError } from "axios" export const createSchedule = async ( from: Date, @@ -11,11 +13,22 @@ export const createSchedule = async ( video: e.video.id, })) - const response = await api.post("/scheduling/jukebox", { - from: from.toISOString(), - to: to.toISOString(), - entries: mappedEntries, - }) + try { + const response = await api.post("/scheduling/jukebox", { + from: from.toISOString(), + to: to.toISOString(), + entries: mappedEntries, + }) - return response.data + return response.data + } catch (error: any) { + // Log the status code if it's an Axios error + if (error.isAxiosError) { + const axiosError = error as AxiosError + log.error(`Error ${axiosError.response?.status}`, { + response: axiosError.response?.data, + }) + } + throw error + } }