Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
toresbe committed Aug 8, 2023
1 parent add5269 commit c75e2ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -35,7 +36,7 @@ const main = async () => {
log.info(result)
} catch (error: any) {
log.error(error.message)
throw error
exit(1)
}
}

Expand Down
25 changes: 19 additions & 6 deletions src/modules/scheduling/helpers/createSchedule.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
}
}

0 comments on commit c75e2ea

Please sign in to comment.