You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -230,7 +230,9 @@ tradfri.reset();
230
230
```
231
231
After a connection loss or reboot of another endpoint, the currently active connection params might no longer be valid. In this case, use the reset method to invalidate the stored connection params, so the next request will use a fresh connection.
232
232
233
-
This causes all requests to be dropped and clears all observations.
233
+
This causes all requests to be dropped and clears all observations.
234
+
235
+
**Note:** Promises belonging to any pending connections, requests or observers will not be fulfilled anymore and you should delete all references to them. In that case, the `"error"` event will be emitted (once or multiple times) with an error with code `TradfriClient.NetworkReset`.
The `"error"` event gets emitted when something unexpected happens. The callback has the following form.
276
279
```TS
277
280
typeErrorCallback= (e:Error) =>void;
278
281
```
279
-
This doesn't have to be fatal and can be called when an unexpected response code is received.
282
+
This doesn't have to be fatal, so you should check which kind of error happened.
283
+
Some errors are of the type `TradfriError` and contain a code which provides more information about the nature of the error. To check that, add `TradfriError` and `TradfriErrorCodes` to the list of imports and check as follows:
284
+
```TS
285
+
if (einstanceofTradfriError) {
286
+
// handle the error depending on `e.code`
287
+
} else {
288
+
// handle the error as you normally would.
289
+
}
290
+
```
291
+
The currently supported error codes are:
292
+
*`TradfriErrorCode.NetworkReset`: The `reset()` method was called while some requests or connection attempts were still pending. Those promises will not be fulfilled anymore, and you should delete all references to them.
280
293
281
294
### Observe a resource
282
295
The standard way to receive updates to a Trådfri (or CoAP) resource is by observing it. The TradfriClient provides a couple of methods to observe resources, with the most generic one being
@@ -489,6 +502,9 @@ A DeviceInfo object contains general information about a device. It has the foll
489
502
490
503
## Changelog
491
504
505
+
#### NEXT:
506
+
* (AlCalzone) Swallow `"CoapClient was reset"` promise rejections and emit an `"error"` instead
507
+
492
508
#### 0.9.1 (2018-03-09)
493
509
* (AlCalzone) Fix properties which are wrongly reported by the gateway
// The CoAP client was reset. This happens when the user
610
+
// resets the CoAP client while connections or requests
611
+
// are still pending. It's not an error per se, so just
612
+
// inform the user about what happened.
613
+
this.emit("error",newtradfri_error_1.TradfriError("The network stack was reset. Pending promises will not be fulfilled.",tradfri_error_1.TradfriErrorCodes.NetworkReset));
614
+
}
615
+
else{
616
+
reject(e);
617
+
}
618
+
}
619
+
}));
620
+
}
599
621
}
600
622
exports.TradfriClient=TradfriClient;
601
623
/** Normalizes the path to a resource, so it can be used for storing the observer */
0 commit comments