finished skip any error from tuya device

This commit is contained in:
faris Aljohari
2024-11-24 17:47:47 -06:00
parent 67ed5cdca1
commit 99bacbe202
3 changed files with 42 additions and 20 deletions
+12 -5
View File
@@ -26,8 +26,8 @@ export class SpaceDeviceService {
spaceUuid,
);
const detailedDevices = await Promise.all(
space.devices.map(async (device) => {
const safeFetch = async (device: any) => {
try {
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
device.deviceTuyaUuid,
);
@@ -41,11 +41,18 @@ export class SpaceDeviceService {
updatedAt: device.updatedAt,
...tuyaDetails,
};
}),
);
} catch (error) {
console.warn(
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error.`,
);
return null;
}
};
const detailedDevices = await Promise.all(space.devices.map(safeFetch));
return new SuccessResponseDto({
data: detailedDevices,
data: detailedDevices.filter(Boolean), // Remove null or undefined values
message: 'Successfully retrieved list of devices',
});
} catch (error) {
@@ -33,8 +33,8 @@ export class SubspaceDeviceService {
const subspace = await this.findSubspaceWithDevices(subSpaceUuid);
const detailedDevices = await Promise.all(
subspace.devices.map(async (device) => {
const safeFetch = async (device: any) => {
try {
const tuyaDetails = await this.getDeviceDetailsByDeviceIdTuya(
device.deviceTuyaUuid,
);
@@ -49,11 +49,17 @@ export class SubspaceDeviceService {
updatedAt: device.updatedAt,
...tuyaDetails,
};
}),
);
} catch (error) {
console.warn(
`Skipping device with deviceTuyaUuid: ${device.deviceTuyaUuid} due to error.`,
);
return null;
}
};
const detailedDevices = await Promise.all(subspace.devices.map(safeFetch));
return new SuccessResponseDto({
data: detailedDevices,
data: detailedDevices.filter(Boolean), // Remove nulls
message: 'Successfully retrieved list of devices',
});
}