Fetch settings only when ready (#5052)

This commit is contained in:
John Richmond 2025-06-23 11:47:27 -07:00 committed by GitHub
parent 041c28d8e5
commit 9b40829922
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,8 +25,7 @@ export class SettingsService {
this.timer = new RefreshTimer({
callback: async () => {
await this.fetchSettings(callback)
return true
return await this.fetchSettings(callback)
},
successInterval: 30000,
initialBackoffMs: 1000,
@ -42,10 +41,6 @@ export class SettingsService {
this.removeSettings()
}
this.authService.on("attempting-session", () => {
this.timer.start()
})
this.authService.on("active-session", () => {
this.timer.start()
})
@ -55,16 +50,16 @@ export class SettingsService {
this.removeSettings()
})
if (this.authService.hasOrIsAcquiringActiveSession()) {
if (this.authService.hasActiveSession()) {
this.timer.start()
}
}
private async fetchSettings(callback: () => void): Promise<void> {
private async fetchSettings(callback: () => void): Promise<boolean> {
const token = this.authService.getSessionToken()
if (!token) {
return
return false
}
try {
@ -76,7 +71,7 @@ export class SettingsService {
if (!response.ok) {
console.error(`Failed to fetch organization settings: ${response.status} ${response.statusText}`)
return
return false
}
const data = await response.json()
@ -84,7 +79,7 @@ export class SettingsService {
if (!result.success) {
console.error("Invalid organization settings format:", result.error)
return
return false
}
const newSettings = result.data
@ -94,8 +89,11 @@ export class SettingsService {
await this.cacheSettings()
callback()
}
return true
} catch (error) {
console.error("Error fetching organization settings:", error)
return false
}
}