Skip to content

Commit

Permalink
improve error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DutchmanNL committed Aug 6, 2023
1 parent 9e7cf05 commit 3326377
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Vedirect extends utils.Adapter {
} catch (error) {
this.log.error('Connection to VE.Direct device failed !');
this.setState('info.connection', false, true);
this.log.error(error);
this.errorHandler(error);
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ class Vedirect extends utils.Adapter {
} catch (error) {
this.log.error('Connection to VE.Direct device failed !');
this.setState('info.connection', false, true);
this.log.error(error);
this.errorHandler(error);
}
}

Expand Down Expand Up @@ -387,7 +387,7 @@ class Vedirect extends utils.Adapter {
*/
stateSetCreate(stateName, name, value) {
this.log.debug('[stateSetCreate]' + stateName + ' with value : ' + value);
const expireTime = 0;
// const expireTime = 0;
try {
// Try to get details from state lib, if not use defaults. throw warning is states is not known in attribute list
const common = {};
Expand Down Expand Up @@ -464,6 +464,18 @@ class Vedirect extends utils.Adapter {
}
}

errorHandler(source, error, debugMode) {
let message = error;
if (error instanceof Error && error.stack != null) message = error.stack;
if (!debugMode) {
this.log.error(`${source} ${error}`);
this.sendSentry(`${message}`);
} else {
this.log.error(`${source} ${error}`);
this.log.debug(`${source} ${message}`);
}
}

/**
* Send error's to sentry, only if sentry not disabled
* @param {string} msg ID of the state
Expand Down

0 comments on commit 3326377

Please sign in to comment.