Skip to content

Commit 7cc630f

Browse files
author
Stefania
committed
improved error handling
1 parent 0769f8e commit 7cc630f

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/daemon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class Daemon {
3333
this.agentInfo = {};
3434
this.agentFound = new BehaviorSubject(null);
3535
this.channelOpen = new BehaviorSubject(null);
36-
this.error = new Subject();
36+
this.error = new BehaviorSubject(null);
3737

3838
this.appMessages = new Subject();
3939
this.serialMonitorOpened = new BehaviorSubject(false);

src/socket-daemon.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { filter, takeUntil, first } from 'rxjs/operators';
2828
import Daemon from './daemon';
2929

3030
// Required agent version
31-
const MIN_VERSION = '1.1.71';
31+
const MIN_VERSION = '1.1.72';
3232
const browser = detect();
3333
const POLLING_INTERVAL = 2500;
3434
const UPLOAD_DONE_TIMER = 5000;
@@ -157,10 +157,7 @@ export default class SocketDaemon extends Daemon {
157157
if (updateAttempts < 4) {
158158
return timer(10000).subscribe(() => this.update());
159159
}
160-
const currentError = this.error.getValue();
161-
if (currentError !== 'plugin version incompatible') {
162-
this.error.next('plugin version incompatible');
163-
}
160+
this.error.next('plugin version incompatible');
164161
return Promise.reject(new Error('plugin version incompatible'));
165162
}
166163

@@ -251,15 +248,19 @@ export default class SocketDaemon extends Daemon {
251248
headers: {
252249
'Content-Type': 'text/plain; charset=utf-8'
253250
}
254-
}).then(() => Promise.reject()) // We reject the promise because the daemon will be restarted, we need to continue looking for the port
255-
.catch(err => {
256-
if (err && err.data && err.data.error && (err.data.error.indexOf('proxy') !== -1 || err.data.error.indexOf('dial tcp') !== -1)) {
257-
const currentError = this.error.getValue();
258-
if (currentError !== 'proxy error') {
251+
})
252+
.then(result => result.json())
253+
.then(response => {
254+
if (!response.ok) {
255+
if (response && response.error && (response.error.indexOf('proxy') !== -1 || response.error.indexOf('dial tcp') !== -1)) {
259256
this.error.next('proxy error');
257+
return new Error('proxy error');
260258
}
261259
}
262-
});
260+
// We reject the promise because the daemon will be restarted, we need to continue looking for the port
261+
return Promise.reject();
262+
})
263+
.catch(err => Promise.reject(err));
263264
}
264265

265266
/**

test/app.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class App extends React.Component {
315315

316316
<div className="section">
317317
<h2>Errors</h2>
318-
<div>{ this.state.error }</div>
318+
<div className="error">{ this.state.error }</div>
319319
</div>
320320
</div>
321321
);

0 commit comments

Comments
 (0)