From adf738a1c1a8951cb2be98f4b207e6ba8a410029 Mon Sep 17 00:00:00 2001 From: tyze <36153252+tyzesc@users.noreply.github.com> Date: Fri, 10 Jun 2022 16:22:48 +0800 Subject: [PATCH] Add "Missing SESSION_TOKEN" exception. --- src/youtube-studio-api.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/youtube-studio-api.js b/src/youtube-studio-api.js index 355daf9..d0c8ac5 100644 --- a/src/youtube-studio-api.js +++ b/src/youtube-studio-api.js @@ -381,6 +381,21 @@ async function getEndScreen(videoId) { async function upload(options) { + // + // @tyzesc + // + // Fix GitHub issue #21 + // https://github.com/adasq/youtube-studio/issues/21 + // + // Missing SESSION_TOKEN will make YouTube return 401 Unauthorized Error, + // and uploadFile pass null value to node-fetch and will cause error. + // + if (typeof sessionToken !== 'string' || sessionToken.length === 0) { + throw { + text: 'Missing SESSION_TOKEN on init will cause Unauthorized Request. Please check your SESSION_TOKEN is set correctly in init function.' + } + } + return uploadFile(options, headers, config, sessionToken) } @@ -619,4 +634,4 @@ module.exports = { setInfoCards, getVideoClaims, upload -} \ No newline at end of file +}