Skip to content

Commit 4ba3a16

Browse files
committed
decouple error handling into it's own method
1 parent 6e922e6 commit 4ba3a16

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/helpers/deviceId.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,7 @@ export class DeviceIdService {
113113
const deviceId = await getDeviceId({
114114
getMachineId: this.getMachineId,
115115
onError: (reason, error) => {
116-
switch (reason) {
117-
case "resolutionError":
118-
this.logger.debug({
119-
id: LogId.telemetryDeviceIdFailure,
120-
context: "deviceId",
121-
message: `Device ID resolution error: ${String(error)}`,
122-
});
123-
break;
124-
case "timeout":
125-
this.logger.debug({
126-
id: LogId.telemetryDeviceIdTimeout,
127-
context: "deviceId",
128-
message: "Device ID retrieval timed out",
129-
});
130-
break;
131-
case "abort":
132-
// No need to log in the case of aborts
133-
break;
134-
}
116+
this.handleDeviceIdError(reason, error);
135117
},
136118
abortSignal: this.abortController.signal,
137119
});
@@ -158,4 +140,31 @@ export class DeviceIdService {
158140
this.abortController = undefined;
159141
}
160142
}
143+
144+
/**
145+
* Handles device ID error.
146+
* @param reason - The reason for the error
147+
* @param error - The error object
148+
*/
149+
private handleDeviceIdError(reason: string, error: Error): void {
150+
switch (reason) {
151+
case "resolutionError":
152+
this.logger.debug({
153+
id: LogId.telemetryDeviceIdFailure,
154+
context: "deviceId",
155+
message: `Device ID resolution error: ${String(error)}`,
156+
});
157+
break;
158+
case "timeout":
159+
this.logger.debug({
160+
id: LogId.telemetryDeviceIdTimeout,
161+
context: "deviceId",
162+
message: "Device ID retrieval timed out",
163+
});
164+
break;
165+
case "abort":
166+
// No need to log in the case of aborts
167+
break;
168+
}
169+
}
161170
}

0 commit comments

Comments
 (0)