api-client/turnstile: don't retry making session if it's not needed

This commit is contained in:
dumbmoron 2024-09-14 19:11:53 +00:00
parent 5d7cd861f3
commit 95f0fbdb5e
No known key found for this signature in database

View file

@ -26,17 +26,20 @@ export class TurnstileCobaltAPI extends CobaltAPI {
}
async request(data: CobaltRequest) {
const sessionOrError = await this.#session.getSession();
const headers: Record<string, string> = {};
if ("error" in sessionOrError) {
if (sessionOrError.error.code !== CobaltAuthError.NotConfigured) {
return sessionOrError;
if (this.#instanceHasTurnstile) {
const sessionOrError = await this.#session.getSession();
if ("error" in sessionOrError) {
if (sessionOrError.error.code !== CobaltAuthError.NotConfigured) {
return sessionOrError;
} else {
this.#instanceHasTurnstile = false;
}
} else {
this.#instanceHasTurnstile = false;
headers['Authorization'] = `Bearer ${sessionOrError.token}`;
}
} else {
headers['Authorization'] = `Bearer ${sessionOrError.token}`;
}
return super.request(data, headers);