Skip to content

Commit

Permalink
feat: add env check and error throw
Browse files Browse the repository at this point in the history
  • Loading branch information
izayl committed Aug 13, 2022
1 parent 4e7b123 commit 4063a93
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,25 @@ const octo = new Octokit({
})

async function main() {
envCheck()
const json = await getTopTracks()
await updateTopTracks(json)
}

async function envCheck() {
if (!GH_TOKEN || !GIST_ID) {
throw new Error(
`
spotify-box ran into an issue for getting your Environment Secrets
Please make sure you have the following Environment Secrets set:
GH_TOKEN
GIST_ID
For more information, see the README.md: https://github.com/izayl/spotify-box#-environment-secrets
`
)
}
}

async function updateTopTracks(json) {
let gist
try {
Expand All @@ -25,7 +40,7 @@ async function updateTopTracks(json) {
console.error(
`spotify-box ran into an issue for getting your gist ${gist_id}:\n${error}`
)
return
throw error
}

const tracks = json.items.map(item => ({
Expand Down Expand Up @@ -62,6 +77,7 @@ async function updateTopTracks(json) {
console.error(
`spotify-box ran into an issue for updating your gist:\n${error}`
)
throw error
}
}

Expand Down

0 comments on commit 4063a93

Please sign in to comment.