Skip to content

Commit

Permalink
Properly handle Connection Errors (#569)
Browse files Browse the repository at this point in the history
* ignore first 500 error

* properly check for connection errors

* check against connecting state as well
  • Loading branch information
UnchartedBull committed Apr 29, 2020
1 parent 5552e68 commit b31909d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/app/standby/standby.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down

0 comments on commit b31909d

Please sign in to comment.