Improve upliad script error handling for token

pull/1104/merge
Chocobozzz 2018-09-26 15:16:48 +02:00
parent 9ffdd52a95
commit 542e73a26b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 12 additions and 4 deletions

View File

@ -75,7 +75,10 @@ getSettings()
process.exit(-1)
}
run().catch(err => console.error(err))
run().catch(err => {
console.error(err)
process.exit(-1)
})
})
async function run () {
@ -90,8 +93,13 @@ async function run () {
password: program[ 'password' ]
}
const res2 = await login(program[ 'url' ], client, user)
const accessToken = res2.body.access_token
let accessToken: string
try {
const res2 = await login(program[ 'url' ], client, user)
accessToken = res2.body.access_token
} catch (err) {
throw new Error('Cannot authenticate. Please check your username/password.')
}
await access(program[ 'file' ], constants.F_OK)
@ -114,7 +122,7 @@ async function run () {
support: undefined
}
await uploadVideo(program['url'], accessToken, videoAttributes)
await uploadVideo(program[ 'url' ], accessToken, videoAttributes)
console.log(`Video ${program['videoName']} uploaded.`)
process.exit(0)