Cloud: settings fetch logging improvements (#5056)

This commit is contained in:
John Richmond 2025-06-23 13:26:26 -07:00 committed by GitHub
parent 609df58831
commit 6670e1abba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

View file

@ -46,8 +46,11 @@ export class CloudService {
this.authService.on("logged-out", this.authListener)
this.authService.on("user-info", this.authListener)
this.settingsService = new SettingsService(this.context, this.authService, () =>
this.callbacks.stateChanged?.(),
this.settingsService = new SettingsService(
this.context,
this.authService,
() => this.callbacks.stateChanged?.(),
this.log,
)
this.settingsService.initialize()

View file

@ -18,10 +18,17 @@ export class SettingsService {
private authService: AuthService
private settings: OrganizationSettings | undefined = undefined
private timer: RefreshTimer
private log: (...args: unknown[]) => void
constructor(context: vscode.ExtensionContext, authService: AuthService, callback: () => void) {
constructor(
context: vscode.ExtensionContext,
authService: AuthService,
callback: () => void,
log?: (...args: unknown[]) => void,
) {
this.context = context
this.authService = authService
this.log = log || console.log
this.timer = new RefreshTimer({
callback: async () => {
@ -70,7 +77,11 @@ export class SettingsService {
})
if (!response.ok) {
console.error(`Failed to fetch organization settings: ${response.status} ${response.statusText}`)
this.log(
"[cloud-settings] Failed to fetch organization settings:",
response.status,
response.statusText,
)
return false
}
@ -78,7 +89,7 @@ export class SettingsService {
const result = organizationSettingsSchema.safeParse(data)
if (!result.success) {
console.error("Invalid organization settings format:", result.error)
this.log("[cloud-settings] Invalid organization settings format:", result.error)
return false
}
@ -92,7 +103,7 @@ export class SettingsService {
return true
} catch (error) {
console.error("Error fetching organization settings:", error)
this.log("[cloud-settings] Error fetching organization settings:", error)
return false
}
}

View file

@ -135,7 +135,12 @@ describe("CloudService", () => {
expect(cloudService).toBeInstanceOf(CloudService)
expect(AuthService).toHaveBeenCalledWith(mockContext, expect.any(Function))
expect(SettingsService).toHaveBeenCalledWith(mockContext, mockAuthService, expect.any(Function))
expect(SettingsService).toHaveBeenCalledWith(
mockContext,
mockAuthService,
expect.any(Function),
expect.any(Function),
)
})
it("should throw error if instance already exists", async () => {