Handle exception in getting device status

This commit is contained in:
Stefano Brilli 2020-09-24 15:27:15 +02:00
parent f8e0539fbb
commit 78fcece557
2 changed files with 13 additions and 4 deletions

View File

@ -37,8 +37,12 @@ export function control(action: 'play' | 'stop' | 'next' | 'prev' | 'goto', para
// CAVEAT: change-track might take a up to a few seconds to complete.
// We wait 500ms and let the monitor do further updates
await sleep(500);
let deviceStatus = await serviceRegistry.netmdService!.getDeviceStatus();
dispatch(mainActions.setDeviceStatus(deviceStatus));
try {
let deviceStatus = await serviceRegistry.netmdService!.getDeviceStatus();
dispatch(mainActions.setDeviceStatus(deviceStatus));
} catch (e) {
console.log('control: Cannot get device status');
}
};
}
@ -80,7 +84,12 @@ export function listContent() {
dispatch(appStateActions.setLoading(true));
let disc = await serviceRegistry.netmdService!.listContent();
let deviceName = await serviceRegistry.netmdService!.getDeviceName();
let deviceStatus = await serviceRegistry.netmdService!.getDeviceStatus();
let deviceStatus = null;
try {
deviceStatus = await serviceRegistry.netmdService!.getDeviceStatus();
} catch (e) {
console.log('listContent: Cannot get device status');
}
dispatch(
batchActions([
mainActions.setDisc(disc),

View File

@ -24,7 +24,7 @@ export const slice = createSlice({
setDeviceName: (state, action: PayloadAction<string>) => {
state.deviceName = action.payload;
},
setDeviceStatus: (state, action: PayloadAction<DeviceStatus>) => {
setDeviceStatus: (state, action: PayloadAction<DeviceStatus | null>) => {
state.deviceStatus = action.payload;
},
},