Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Sep 25, 2023
1 parent 34d504a commit 66de98c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 96 deletions.
72 changes: 2 additions & 70 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,71 +1,3 @@
{
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"curly": "error",
"brace-style": "error",
"arrow-parens": [
"error",
"as-needed"
],
"no-console": "off",
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"no-useless-escape": "warn",
"no-constant-condition": "off",
"no-multiple-empty-lines": [
"error",
{
"max": 1,
"maxEOF": 1
}
],
"no-var": "error",
"prefer-const": "error",
"no-throw-literal": "error",
"prefer-promise-reject-errors": "error",
"quotes": [
"error",
"single",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"semi": [
"error",
"always"
],
"comma-dangle": [
"error",
{
"arrays": "never",
"objects": "never",
"imports": "never",
"exports": "never",
"functions": "ignore"
}
],
"no-trailing-spaces": "error"
},
"parserOptions": {
"ecmaVersion": 2019
}
}
"extends": ["@foxriver76/eslint-config"]
}
12 changes: 0 additions & 12 deletions .prettierrc.json

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ For every shopping list a channel with the following states will be created:
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
* (foxriver76) Improve error messages

### 1.8.2 (2023-09-24)
* (foxriver76) do not crash on invalid `setState` calls (closes #211)

Expand Down
28 changes: 14 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function startAdapter(options) {
if (obj && obj.command === `getTelegramUsers`) {
try {
const state = await adapter.getForeignStateAsync(`${obj.message}.communicate.users`);
if (state && state.val) {
if (state?.val) {
adapter.sendTo(obj.from, obj.command, state.val, obj.callback);
}
} catch (e) {
Expand All @@ -48,7 +48,7 @@ function startAdapter(options) {
adapter.log.info(`[END] Stopping Bring! adapter...`);
adapter.setState(`info.connection`, false, true);
callback();
} catch (e) {
} catch {
callback();
}
});
Expand All @@ -65,7 +65,7 @@ function startAdapter(options) {
}

lang = obj && obj.common && obj.common.language ? obj.common.language : `en`;
} catch (e) {
} catch {
lang = `en`;
password = crypto.decrypt(`Zgfr56gFe87jJOM`, adapter.config.password);
mail = crypto.decrypt(`Zgfr56gFe87jJOM`, adapter.config.mail);
Expand Down Expand Up @@ -146,7 +146,7 @@ async function main() {
}
}
} catch (e) {
adapter.log.warn(e);
adapter.log.warn(`Error loading translations: ${e.message}`);
}

// Start polling, this goes endless
Expand Down Expand Up @@ -190,7 +190,7 @@ async function pollList(listUuid) {
);
await adapter.setState(`${listUuid}.count`, data.purchase.length, true);
} catch (e) {
adapter.log.warn(e);
adapter.log.warn(`Error polling items for list "${listUuid}": ${e.message}`);
adapter.setStateChanged(`info.connection`, false, true);
}

Expand All @@ -205,7 +205,7 @@ async function pollList(listUuid) {
await adapter.setState(`${listUuid}.usersHtml`, usersHtml, true);
await adapter.setState(`${listUuid}.usersHtmlNoHead`, `<table>${usersHtml.split(`</thead>`)[1]}`, true);
} catch (e) {
adapter.log.warn(e);
adapter.log.warn(`Error getting users from list "${listUuid}": ${e.message}`);
adapter.setStateChanged(`info.connection`, false, true);
}
}
Expand Down Expand Up @@ -310,7 +310,7 @@ async function pollAllLists() {
}
} catch (e) {
adapter.setStateChanged(`info.connection`, false, true);
adapter.log.warn(e);
adapter.log.warn(`Error polling all lists: ${e.message}`);
// Check if Access token no longer valid
if (e.message.includes(`JWT access token is not valid`)) {
tryLogin();
Expand All @@ -320,7 +320,7 @@ async function pollAllLists() {
if (polling.all) {
clearTimeout(polling.all);
}
polling.all = setTimeout(pollAllLists, 90000);
polling.all = setTimeout(pollAllLists, 90_000);
}

async function tryLogin() {
Expand All @@ -334,12 +334,12 @@ async function tryLogin() {
}
return Promise.resolve();
} catch (e) {
adapter.log.warn(e);
adapter.log.warn(`Error on login: ${e.message}`);
adapter.log.info(`[LOGIN] Reconnection in 30 seconds`);
if (loginTimeout) {
clearTimeout(loginTimeout);
}
loginTimeout = setTimeout(tryLogin, 30000);
loginTimeout = setTimeout(tryLogin, 30_000);
}
}

Expand Down Expand Up @@ -412,7 +412,7 @@ async function removeItem(listId, article, translate) {
await adapter.setState(`${listId}.${translate ? 'removeItemTranslated' : 'removeItem'}`, article, true);
} catch (e) {
adapter.setStateChanged(`info.connection`, false, true);
adapter.log.warn(e.message);
adapter.log.warn(`Error removing item "${article}" from list "${listId}": ${e.message}`);
}
}

Expand Down Expand Up @@ -448,7 +448,7 @@ async function saveItem(listId, articleWithDescription, translate) {
);
} catch (e) {
adapter.setStateChanged(`info.connection`, false, true);
adapter.log.warn(e.message);
adapter.log.warn(`Error saving item "${articleWithDescription}" to list "${listId}": ${e.message}`);
}
}

Expand Down Expand Up @@ -480,7 +480,7 @@ async function moveToRecentContent(listId, article, translate) {
);
} catch (e) {
adapter.setStateChanged(`info.connection`, false, true);
adapter.log.warn(e.message);
adapter.log.warn(`Error moving article "${article}" on list "${listId}" to recent content ${e.message}`);
}
}

Expand All @@ -501,7 +501,7 @@ async function sendShoppingList(listId) {
} - ${dict[entry.name] ? dict[entry.name] : entry.name}\n`;
}
} catch (e) {
adapter.log.error(`Error sending shopping list: ${e}`);
adapter.log.error(`Error sending shopping list: ${e.message}`);
return;
}

Expand Down
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@foxriver76/eslint-config/prettier');

0 comments on commit 66de98c

Please sign in to comment.