-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
add error handling to weather fetch functions, including cors #3791
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
base: develop
Are you sure you want to change the base?
Conversation
all tests run locally, electron and e2e |
the 2 failed tests are unit tests - and they fail if I run them locally ... |
Running this patch locally with success thus far.... Thanks! |
modules/default/utils.js
Outdated
if (type === "xml") { | ||
return new DOMParser().parseFromString(data, "text/html"); | ||
} else { | ||
if (!data || !data.length > 0) return "null"; //undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return "null"
as a string looks unusual. Can you explain why you did this and why there is a comment // undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at suggested error recovery, the undefined prior result (comment) is faulty
Leading to a secondary error masking the first (no data)
And null in quotes is the recommended change
I don't understand that (or undefined) either, as none of these are JSON , or error (throw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and looking at the provider that calls the performWebRequest (here looking at pirateweather)
fetchWeatherForecast () {
this.fetchData(this.getUrl())
.then((data) => {
if (!data || !data.daily || !data.daily.data.length) { // undefined or null (no quotes)
// No usable data?
return; // <----- I think this bypasses the finally, so the provider is waiting forever, hung
}
const forecast = this.generateWeatherObjectsFromForecast(data.daily.data);
this.setWeatherForecast(forecast);
})
.catch(function (request) { // <--- maybe throw is a better choice
Log.error("Could not load data ... ", request);
})
.finally(() => this.updateAvailable());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the fetchData in the providers layer
async fetchData (url, type = "json", requestHeaders = undefined, expectedResponseHeaders = undefined) {
const mockData = this.config.mockData;
if (mockData) {
const data = mockData.substring(1, mockData.length - 1);
return JSON.parse(data);
}
const useCorsProxy = typeof this.config.useCorsProxy !== "undefined" && this.config.useCorsProxy;
return performWebRequest(url, type, useCorsProxy, requestHeaders, expectedResponseHeaders, config.basePath);
}
Every other provider had to be fixed as well |
@sdetweil I worked on a solution and pushed it directly into your branch. I hope that's okay(?) Unfortunately, I was not able to provoke the error before and after this PR, but the tests are now running again. Can you check if the error occurs with it? |
I saw. Will try to test today. I had forced the error path |
@sdetweil What do you think? Can we merge this? |
let me do some testing, been pretty busy lately |
No problem. Take your time 🙂 |
add error detection and handling for weather and cors fetch
fixes #3687