Skip to content

Commit d4e4683

Browse files
authored
feat(Session): Add fail_fast option (#1066)
1 parent 7eb062b commit d4e4683

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/core/Session.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export type SessionOptions = {
169169
* If you want to force a new session to be generated, you must clear the cache or disable session caching.
170170
*/
171171
generate_session_locally?: boolean;
172+
/**
173+
* If set to `true`, session creation will fail if it's not possible to retrieve session data from YouTube.
174+
* If `false`, a local fallback will be used.
175+
*/
176+
fail_fast?: boolean;
172177
/**
173178
* Specifies whether the session data should be cached.
174179
*/
@@ -301,6 +306,7 @@ export default class Session extends EventEmitter {
301306
options.user_agent,
302307
options.enable_safety_mode,
303308
options.generate_session_locally,
309+
options.fail_fast,
304310
options.device_category,
305311
options.client_type,
306312
options.timezone,
@@ -381,6 +387,7 @@ export default class Session extends EventEmitter {
381387
user_agent: string = getRandomUserAgent('desktop'),
382388
enable_safety_mode = false,
383389
generate_session_locally = false,
390+
fail_fast = false,
384391
device_category: DeviceCategory = 'desktop',
385392
client_name: ClientType = ClientType.WEB,
386393
tz: string = Intl.DateTimeFormat().resolvedOptions().timeZone,
@@ -446,6 +453,8 @@ export default class Session extends EventEmitter {
446453
api_version = sw_session_data.api_version;
447454
context_data = sw_session_data.context_data;
448455
} catch (error) {
456+
if (fail_fast)
457+
throw error;
449458
Log.error(TAG, 'Failed to retrieve session data from server. Session data generated locally will be used instead.', error);
450459
}
451460
}

0 commit comments

Comments
 (0)