mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Refaktor newsfeed error once again for better messaging to the user
This commit is contained in:
parent
aeefe28710
commit
d43a57af36
@ -122,6 +122,14 @@ NodeHelper.checkFetchStatus = function (response) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NodeHelper.checkFetchError = function (error) {
|
||||||
|
let error_type = "MODULE_ERROR_UNSPECIFIED";
|
||||||
|
if (error.code === "EAI_AGAIN") {
|
||||||
|
error_type = "MODULE_ERROR_NO_CONNECTION";
|
||||||
|
}
|
||||||
|
return error_type;
|
||||||
|
};
|
||||||
|
|
||||||
NodeHelper.create = function (moduleDefinition) {
|
NodeHelper.create = function (moduleDefinition) {
|
||||||
return NodeHelper.extend(moduleDefinition);
|
return NodeHelper.extend(moduleDefinition);
|
||||||
};
|
};
|
||||||
|
@ -89,11 +89,8 @@ Module.register("newsfeed", {
|
|||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
} else if (notification === "FETCH_ERROR") {
|
} else if (notification === "NEWSFEED_ERROR") {
|
||||||
this.error = `${payload.error}`;
|
this.error = this.translate(payload.error_type);
|
||||||
this.scheduleUpdateInterval();
|
|
||||||
} else if (notification === "INCORRECT_URL") {
|
|
||||||
this.error = `Incorrect url: ${payload.url}`;
|
|
||||||
this.scheduleUpdateInterval();
|
this.scheduleUpdateInterval();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -90,7 +90,7 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
|
|||||||
response.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
response.body.pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
fetchFailedCallback(this, error.message);
|
fetchFailedCallback(this, error);
|
||||||
scheduleTimer();
|
scheduleTimer();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,8 @@ module.exports = NodeHelper.create({
|
|||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.sendSocketNotification("INCORRECT_URL", { url: url });
|
Log.error("Newsfeed Error. Malformed newsfeed url: ", url, error);
|
||||||
|
this.sendSocketNotification("NEWSFEED_ERROR", { error_type: "MODULE_ERROR_MALFORMED_URL" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,10 +53,10 @@ module.exports = NodeHelper.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
fetcher.onError((fetcher, error) => {
|
fetcher.onError((fetcher, error) => {
|
||||||
Log.error("Newsfeed Error. Could not fetch newsfeed: ", fetcher.url(), error);
|
Log.error("Newsfeed Error. Could not fetch newsfeed: ", url, error);
|
||||||
this.sendSocketNotification("FETCH_ERROR", {
|
let error_type = NodeHelper.checkFetchError(error);
|
||||||
url: fetcher.url(),
|
this.sendSocketNotification("NEWSFEED_ERROR", {
|
||||||
error: error
|
error_type
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
"MODULE_CONFIG_CHANGED": "The configuration options for the {MODULE_NAME} module have changed.\nPlease check the documentation.",
|
"MODULE_CONFIG_CHANGED": "The configuration options for the {MODULE_NAME} module have changed.\nPlease check the documentation.",
|
||||||
"MODULE_CONFIG_ERROR": "Error in the {MODULE_NAME} module. {ERROR}",
|
"MODULE_CONFIG_ERROR": "Error in the {MODULE_NAME} module. {ERROR}",
|
||||||
|
"MODULE_ERROR_MALFORMED_URL": "Malformed url.",
|
||||||
|
"MODULE_ERROR_NO_CONNECTION": "No internet connection.",
|
||||||
|
"MODULE_ERROR_UNSPECIFIED": "Check logs for more details.",
|
||||||
|
|
||||||
"UPDATE_NOTIFICATION": "MagicMirror² update available.",
|
"UPDATE_NOTIFICATION": "MagicMirror² update available.",
|
||||||
"UPDATE_NOTIFICATION_MODULE": "Update available for {MODULE_NAME} module.",
|
"UPDATE_NOTIFICATION_MODULE": "Update available for {MODULE_NAME} module.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user