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,31 +262,42 @@ class SimpleProcessHandlers {
throw new Error('Invalid message type');
}
const processes = this.service.getProcesses();
const myProcesses = await this.service.getMyProcesses();
if (!myProcesses || myProcesses.length === 0) {
throw new Error('No my processes found');
if (!this.service.isPaired()) {
throw new Error('Device not paired');
}
const filteredProcesses: Record<string, Process> = {};
for (const processId of myProcesses) {
const process = processes.get(processId);
console.log(processId, ':', process);
try {
const processes = this.service.getProcesses();
const myProcesses = await this.service.getMyProcesses();
if (process) {
filteredProcesses[processId] = process;
if (!myProcesses || myProcesses.length === 0) {
throw new Error('No my processes found');
}
const filteredProcesses: Record<string, Process> = {};
for (const processId of myProcesses) {
const process = processes.get(processId);
if (process) {
filteredProcesses[processId] = process;
} else {
console.error(`Process ${processId} not found`); // should not happen
}
}
const data = await this.service.getProcessesData(filteredProcesses);
return {
type: MessageType.PROCESSES_RETRIEVED,
processes: filteredProcesses,
data,
messageId: event.data.messageId
};
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e || 'Unknown error');
throw new Error(errorMessage);
}
const data = await this.service.getProcessesData(filteredProcesses);
return {
type: MessageType.PROCESSES_RETRIEVED,
processes: filteredProcesses,
data,
messageId: event.data.messageId
};
}
}
async handleMessage(event: ServerMessageEvent): Promise<ServerResponse> {