Skip to content

Commit 6f73ce9

Browse files
committed
Don't use v2 if it's not available
1 parent a43744a commit 6f73ce9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/socket-daemon.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ export default class SocketDaemon extends Daemon {
6969
.subscribe(agentFound => {
7070
if (agentFound) {
7171
this._wsConnect();
72-
this.v2 = new V2(this.pluginURL);
73-
this.agentV2Found.next(this.v2);
72+
const v2 = new V2(this.pluginURL);
73+
v2.init().then(() => {
74+
this.v2 = v2;
75+
this.agentV2Found.next(this.v2);
76+
});
7477
}
7578
else {
7679
this.findAgent();

src/socket-daemon.v2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ export default class SocketDaemonV2 {
33
this.daemonURL = `${daemonURL}/v2`;
44
}
55

6+
// init tries an HEAD
7+
init() {
8+
return fetch(`${this.daemonURL}/pkgs/tools/installed`, {
9+
method: 'HEAD',
10+
}).then(res => {
11+
if (res.status !== 200) {
12+
throw Error('v2 not available');
13+
}
14+
return res;
15+
});
16+
}
17+
618
// installedTools uses the new v2 apis to ask the daemon a list of the tools already present in the system
719
installedTools() {
820
return fetch(`${this.daemonURL}/pkgs/tools/installed`, {

0 commit comments

Comments
 (0)