cap:error-state
- error reporting¶
The error-state
capability is used when a thing can report an error, such
as a humidifier running out of water or a autonomous vacuum getting stuck.
if(thing.matches('cap:error-state')) {
if(thing.error) {
console.log('Error is:', thing.error);
}
}
API¶
Events¶
-
errorChanged
The current error has changed. The payload will be the current error state as a code or
null
.Example:
thing.on('errorChanged', error => console.log('Error state:', error));
-
error
Emitted when an error occurs. The payload will be the error.
Example:
thing.on('error', error => console.log('Error occured:', error));
-
errorCleared
Emitted when the thing no longer has an error.
Example:
thing.on('errorCleared', () => console.log('Thing no longer has an error'));
Protected methods¶
Implementing capability¶
When implementing this capability the implementor needs to call
updateError
whenever an error state is entered or left.
const { Thing, ErrorState } = require('abstract-things');
class Example extends Thing.with(ErrorState) {
}