Currently I'm using the Weather API introduced in SDK 4.3.0 and used the catch function to collect errors.
This error is sent to my function which checks if the error is "Error: Cannot fetch current location".
However it doesn't say true even though the console prints out "Companion: Error: Cannot fetch current location"
Does anyone have a reliable method of catching these errors?
Thank you
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
weather.catch(ex) => console.error(ex); checkError(ex);
checkError is a function I created to detect errors
function checkError(data) {
let test = data;
console.log(test);
if (checkError === "Error: Cannot fetch current location") {
console.log("trigger success");
}
}
however it doesn't work
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
import { me as companion } from "companion";
import weather from "weather";
if (companion.permissions.granted("access_location")) {
weather
.getWeatherData()
.then(data => {
if (data.locations.length > 0) {
const temp = Math.floor(data.locations[0].currentWeather.temperature);
const cond = data.locations[0].currentWeather.weatherCondition;
const loc = data.locations[0].name;
const unit = data.temperatureUnit;
console.log(`It's ${temp}\u00B0 ${unit} and ${cond}
in ${loc}`);
}
})
.catch(ex => {
checkError(ex);
});
}
function checkError(ex) {
console.error(ex);
// You don't need to check the reason here, it already failed
if (ex === "Error: Cannot fetch current location") {
console.log("trigger success"); //why? it failed already
}
}
Best AnswerI'm using the trigger to catch different weather errors, that's all but if I just need to catch the error that works I guess.
Best AnswerI am having this too, and it makes my clockface crash.
It is important for my clockFace to have weather data, and i know how to catch the error, but i need to fix it
My code is:
if (companion.permissions.granted("access_location")) {
weather.getWeatherData().then((data) => {
if (data.locations.length > 0) {
let temp = 111;
let tempPrev = -222;
tempPrev = temp;
temp = Math.floor(data.locations[0].currentWeather.temperature);
const cond = gettext(util.findWeatherConditionName(WeatherCondition,data.locations[0].currentWeather.weatherCondition));
console.log(util.findWeatherConditionName(WeatherCondition,data.locations[0].currentWeather.weatherCondition));
const loc = data.locations[0].name;
const unit = data.temperatureUnit;
And it throws the (catched) error:
Error: Cannot fetch current location