Skip to content

Commit e5e909a

Browse files
committed
Handle undefined services after timeout
1 parent 92598cb commit e5e909a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/widget.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class NaoRobotModel extends DOMWidgetModel {
8383
this.qiSession = new QiSession(ipAddress, port);
8484

8585
// Timeout after ~10 seconds
86-
for (let i = 0; i < 100; i++) {
86+
for (let i = 0; i < 10; i++) {
8787
if (this.qiSession.isConnected()) {
8888
this.connected = 'Connected';
8989
this.set('connected', 'Connected');
@@ -146,10 +146,18 @@ export class NaoRobotModel extends DOMWidgetModel {
146146

147147
const naoService = await servicePromise
148148
.then((resolution: any) => {
149+
this.send({
150+
isError: false,
151+
data: resolution ?? true,
152+
});
149153
return resolution;
150154
})
151155
.catch((rejection: string) => {
152156
this.changeStatus(rejection);
157+
this.send({
158+
isError: true,
159+
data: rejection,
160+
});
153161
return rejection;
154162
});
155163

@@ -183,6 +191,11 @@ export class NaoRobotModel extends DOMWidgetModel {
183191
await sleep(100);
184192
}
185193

194+
if (this._services[serviceName] === undefined) {
195+
this.changeStatus(serviceName + ' not available.');
196+
return;
197+
}
198+
186199
if (this._services[serviceName][methodName] === undefined) {
187200
this.changeStatus(methodName + ' does not exist for ' + serviceName);
188201
return;

0 commit comments

Comments
 (0)