diff --git a/src/app/plugin-service/enclosure.service.ts b/src/app/plugin-service/enclosure.service.ts index 5677a321d..c912ea900 100644 --- a/src/app/plugin-service/enclosure.service.ts +++ b/src/app/plugin-service/enclosure.service.ts @@ -13,6 +13,7 @@ import { NotificationService } from '../notification/notification.service'; export class EnclosureService { private httpGETRequest: Subscription; private observable: Observable; + private initialRequest = true; public constructor( private http: HttpClient, @@ -20,7 +21,7 @@ export class EnclosureService { private notificationService: NotificationService, ) { this.observable = new Observable((observer: Observer): void => { - timer(2500, 30000).subscribe((): void => { + timer(2500, 15000).subscribe((): void => { if (this.httpGETRequest) { this.httpGETRequest.unsubscribe(); } @@ -33,6 +34,7 @@ export class EnclosureService { ) .subscribe( (data: EnclosurePluginAPI): void => { + this.initialRequest = false; observer.next(({ temperature: data.temp_sensor_temp, humidity: data.temp_sensor_humidity, @@ -40,7 +42,14 @@ export class EnclosureService { } as unknown) as TemperatureReading); }, (error: HttpErrorResponse): void => { - this.notificationService.setError("Can't retrieve enclosure temperature!", error.message); + if (this.initialRequest && error.status === 500) { + this.initialRequest = false; + } else { + this.notificationService.setError( + "Can't retrieve enclosure temperature!", + error.message, + ); + } }, ); }); diff --git a/src/app/standby/standby.component.ts b/src/app/standby/standby.component.ts index 953b01302..f09800166 100644 --- a/src/app/standby/standby.component.ts +++ b/src/app/standby/standby.component.ts @@ -48,7 +48,7 @@ export class StandbyComponent implements OnInit { .post(this.configService.getURL('connection'), connectPayload, this.configService.getHTTPHeaders()) .subscribe( (): void => { - setTimeout(this.checkConnection.bind(this), 3000); + setTimeout(this.checkConnection.bind(this), 5000); }, (): void => { this.setConnectionError(); @@ -60,16 +60,29 @@ export class StandbyComponent implements OnInit { this.http.get(this.configService.getURL('connection'), this.configService.getHTTPHeaders()).subscribe( (data: OctoprintConnectionAPI): void => { if (data.current.state === 'Closed') { - if (this.connectionRetries === 0) { + if (this.connectionRetries <= 0) { this.connectionRetries = 3; this.setConnectionError(); } else { this.connectionRetries--; setTimeout(this.connectToPrinter.bind(this), 500); } - } else if (data.current.state === 'Error') { - this.connectionRetries = 3; - this.setConnectionError(); + } else if (data.current.state.includes('Error')) { + if (this.connectionRetries <= 1) { + this.connectionRetries = 3; + this.setConnectionError(); + } else { + this.connectionRetries--; + setTimeout(this.connectToPrinter.bind(this), 500); + } + } else if (data.current.state === 'Connecting') { + if (this.connectionRetries < 0) { + this.connectionRetries = 3; + this.setConnectionError(); + } else { + this.connectionRetries--; + setTimeout(this.checkConnection.bind(this), 5000); + } } else { this.disableStandby(); }