Skip to content

Commit 6670e1a

Browse files
authored
Cloud: settings fetch logging improvements (#5056)
1 parent 609df58 commit 6670e1a

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

packages/cloud/src/CloudService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ export class CloudService {
4646
this.authService.on("logged-out", this.authListener)
4747
this.authService.on("user-info", this.authListener)
4848

49-
this.settingsService = new SettingsService(this.context, this.authService, () =>
50-
this.callbacks.stateChanged?.(),
49+
this.settingsService = new SettingsService(
50+
this.context,
51+
this.authService,
52+
() => this.callbacks.stateChanged?.(),
53+
this.log,
5154
)
5255
this.settingsService.initialize()
5356

packages/cloud/src/SettingsService.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ export class SettingsService {
1818
private authService: AuthService
1919
private settings: OrganizationSettings | undefined = undefined
2020
private timer: RefreshTimer
21-
22-
constructor(context: vscode.ExtensionContext, authService: AuthService, callback: () => void) {
21+
private log: (...args: unknown[]) => void
22+
23+
constructor(
24+
context: vscode.ExtensionContext,
25+
authService: AuthService,
26+
callback: () => void,
27+
log?: (...args: unknown[]) => void,
28+
) {
2329
this.context = context
2430
this.authService = authService
31+
this.log = log || console.log
2532

2633
this.timer = new RefreshTimer({
2734
callback: async () => {
@@ -70,15 +77,19 @@ export class SettingsService {
7077
})
7178

7279
if (!response.ok) {
73-
console.error(`Failed to fetch organization settings: ${response.status} ${response.statusText}`)
80+
this.log(
81+
"[cloud-settings] Failed to fetch organization settings:",
82+
response.status,
83+
response.statusText,
84+
)
7485
return false
7586
}
7687

7788
const data = await response.json()
7889
const result = organizationSettingsSchema.safeParse(data)
7990

8091
if (!result.success) {
81-
console.error("Invalid organization settings format:", result.error)
92+
this.log("[cloud-settings] Invalid organization settings format:", result.error)
8293
return false
8394
}
8495

@@ -92,7 +103,7 @@ export class SettingsService {
92103

93104
return true
94105
} catch (error) {
95-
console.error("Error fetching organization settings:", error)
106+
this.log("[cloud-settings] Error fetching organization settings:", error)
96107
return false
97108
}
98109
}

packages/cloud/src/__tests__/CloudService.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ describe("CloudService", () => {
135135

136136
expect(cloudService).toBeInstanceOf(CloudService)
137137
expect(AuthService).toHaveBeenCalledWith(mockContext, expect.any(Function))
138-
expect(SettingsService).toHaveBeenCalledWith(mockContext, mockAuthService, expect.any(Function))
138+
expect(SettingsService).toHaveBeenCalledWith(
139+
mockContext,
140+
mockAuthService,
141+
expect.any(Function),
142+
expect.any(Function),
143+
)
139144
})
140145

141146
it("should throw error if instance already exists", async () => {

0 commit comments

Comments
 (0)