Better error management for handleGetMyProcesses
This commit is contained in:
parent
b77dbceaa9
commit
2551c9923a
@ -262,31 +262,42 @@ class SimpleProcessHandlers {
|
|||||||
throw new Error('Invalid message type');
|
throw new Error('Invalid message type');
|
||||||
}
|
}
|
||||||
|
|
||||||
const processes = this.service.getProcesses();
|
if (!this.service.isPaired()) {
|
||||||
const myProcesses = await this.service.getMyProcesses();
|
throw new Error('Device not paired');
|
||||||
|
|
||||||
if (!myProcesses || myProcesses.length === 0) {
|
|
||||||
throw new Error('No my processes found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredProcesses: Record<string, Process> = {};
|
try {
|
||||||
for (const processId of myProcesses) {
|
const processes = this.service.getProcesses();
|
||||||
const process = processes.get(processId);
|
const myProcesses = await this.service.getMyProcesses();
|
||||||
console.log(processId, ':', process);
|
|
||||||
|
|
||||||
if (process) {
|
if (!myProcesses || myProcesses.length === 0) {
|
||||||
filteredProcesses[processId] = process;
|
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> {
|
async handleMessage(event: ServerMessageEvent): Promise<ServerResponse> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user