Skip to content

[owmweather] prevent updating settings.updated when call to OWM fails #3876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

thinkpoop
Copy link
Contributor

Link: https://thinkpoop.github.io/BangleApps/?id=owmweather

In boot.js function onCompleted, the settings.updated value is always updated, even if it's being called during error handing.

Example:
GB gets disconnected.
OWMWeather tries to refresh, gets a timeout, sets settings.updated to now + 1hr.
GB gets reconnected.
OWMWeather checks settings.updated and thinks it doesn't need , even though the data is bad.

@@ -10,14 +10,21 @@
return settings.refresh * 1000 * 60 + 1; // +1 <- leave some slack
};

let onCompleted = function () {
let onCompleted = function (result) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is result used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. But that question made me realize I missed an error situation.

In lib.js, the parseWeather method returns undefined on success, or a string on error.

I've added checking that result and calling the appropriate callback based on it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'm happy to merge but if you wanted there is the option of trimming down a bit too:

       if (result === undefined) {
         if (completionCallback) completionCallback();
       } else {
-        if (errorCallback) errorCallback(result);
+        throw result;
       }
     }).catch((e)=>{
       if (errorCallback) errorCallback(e);

@bobrippling
Copy link
Collaborator

LGTM, one small comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants