fix(dashboard): fix toastr handling error if no dat ain relay
This commit is contained in:
parent
ee463ec174
commit
e0b74fd135
|
|
@ -149,7 +149,7 @@ export class DashboardComponent implements OnInit {
|
||||||
|
|
||||||
this.apiService.getRelayStatus().subscribe(
|
this.apiService.getRelayStatus().subscribe(
|
||||||
(response) => {
|
(response) => {
|
||||||
if (Array.isArray(response.data)) {
|
if (Array.isArray(response.data) && response.data.length > 0) {
|
||||||
this.relayStatus = response.data.map((relay) => ({
|
this.relayStatus = response.data.map((relay) => ({
|
||||||
id: relay.id,
|
id: relay.id,
|
||||||
number: relay.number,
|
number: relay.number,
|
||||||
|
|
@ -159,16 +159,22 @@ export class DashboardComponent implements OnInit {
|
||||||
current_status: relay.current_status
|
current_status: relay.current_status
|
||||||
}));
|
}));
|
||||||
this.relayStatus.sort((a, b) => a.number - b.number);
|
this.relayStatus.sort((a, b) => a.number - b.number);
|
||||||
|
this.noData = false; // Data available
|
||||||
|
} else {
|
||||||
|
// Throw an error if relay data is empty
|
||||||
|
this.handleError({ message: 'No available relay data.' });
|
||||||
|
this.noData = true;
|
||||||
}
|
}
|
||||||
this.isLoaded = false;
|
this.isLoaded = false;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toast.error('Failed to get relay status, please try again');
|
|
||||||
this.hasError = true;
|
|
||||||
this.isLoaded = false;
|
this.isLoaded = false;
|
||||||
|
this.handleError(error);
|
||||||
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
handleError(error: any): void {
|
handleError(error: any): void {
|
||||||
if (this.selectedButton === 'dht') {
|
if (this.selectedButton === 'dht') {
|
||||||
|
|
@ -177,6 +183,8 @@ export class DashboardComponent implements OnInit {
|
||||||
this.toast.error('Error fetching NPK1 sensor data. Please try again.', 'Error', { timeOut: 3000 });
|
this.toast.error('Error fetching NPK1 sensor data. Please try again.', 'Error', { timeOut: 3000 });
|
||||||
} else if (this.selectedButton === 'npk2') {
|
} else if (this.selectedButton === 'npk2') {
|
||||||
this.toast.error('Error fetching NPK2 sensor data. Please try again.', 'Error', { timeOut: 3000 });
|
this.toast.error('Error fetching NPK2 sensor data. Please try again.', 'Error', { timeOut: 3000 });
|
||||||
|
} else if (this.selectedButton === 'relay') {
|
||||||
|
this.toast.error('Error fetching relay status. Please try again.', 'Error', { timeOut: 3000 });
|
||||||
}
|
}
|
||||||
this.hasError = true;
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user