Better error management for handleGetMyProcesses

This commit is contained in:
Sosthene 2025-09-04 04:46:27 +02:00
parent b77dbceaa9
commit 2551c9923a

View File

@ -262,6 +262,11 @@ class SimpleProcessHandlers {
throw new Error('Invalid message type');
}
if (!this.service.isPaired()) {
throw new Error('Device not paired');
}
try {
const processes = this.service.getProcesses();
const myProcesses = await this.service.getMyProcesses();
@ -272,10 +277,11 @@ class SimpleProcessHandlers {
const filteredProcesses: Record<string, Process> = {};
for (const processId of myProcesses) {
const process = processes.get(processId);
console.log(processId, ':', process);
if (process) {
filteredProcesses[processId] = process;
} else {
console.error(`Process ${processId} not found`); // should not happen
}
}
@ -287,6 +293,11 @@ class SimpleProcessHandlers {
data,
messageId: event.data.messageId
};
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
throw new Error(errorMessage);
}
}
}
async handleMessage(event: ServerMessageEvent): Promise<ServerResponse> {