MagicMirrorOrg/MagicMirror · error · Error
Invalid weather data
Error message
Invalid weather data
What it means
smhi's #handleResponse expects the API response to contain a `timeSeries` array (SMHI's point-forecast format). If the parsed data lacks timeSeries or it isn't an array, it throws 'Invalid weather data'. This shields downstream parsers from malformed payloads.
Source
Thrown at defaultmodules/weather/providers/smhi.js:123
this.onErrorCallback({
message: "Failed to parse API response",
translationKey: "MODULE_ERROR_UNSPECIFIED"
});
}
}
});
this.fetcher.on("error", (errorInfo) => {
if (this.onErrorCallback) {
this.onErrorCallback(errorInfo);
}
});
}
#handleResponse (data) {
try {
if (!data.timeSeries || !Array.isArray(data.timeSeries)) {
throw new Error("Invalid weather data");
}
const coordinates = this.#resolveCoordinates(data);
let weatherData;
switch (this.config.type) {
case "current":
weatherData = this.#generateCurrentWeather(data.timeSeries, coordinates);
break;
case "forecast":
case "daily":
weatherData = this.#generateForecast(data.timeSeries, coordinates);
break;
case "hourly":
weatherData = this.#generateHourly(data.timeSeries, coordinates);
break;
default:
Log.error(`[smhi] Unknown weather type: ${this.config.type}`);View on GitHub (pinned to 4b4a59534f)
Solutions
- Verify the SMHI API URL/version matches what the module expects (category/version in the URL)
- Check coordinates are within SMHI's coverage area
- curl the request URL and confirm the body contains "timeSeries"
- Retry later if SMHI is having an outage; check the error callback for the underlying cause
Defensive patterns
Strategy: type-guard
Validate before calling
const looksLikeSmhiPayload = (d) => d != null && Array.isArray(d.timeSeries);
if (!looksLikeSmhiPayload(data)) console.warn("SMHI payload missing timeSeries — check API URL/version and coverage"); Type guard
const hasTimeSeries = (d) => typeof d === "object" && d !== null && Array.isArray(d.timeSeries);
Try / catch
provider.setCallbacks(
(data) => render(data),
(err) => { if (err.message === "Invalid weather data") fallbackProviderOrRetry(); }
); Prevention
- Confirm SMHI category/version in the URL matches the module's expectation
- Check coordinates fall within SMHI's covered area (Sweden)
- Log the raw response body on error to distinguish outage vs schema change
- Handle onError with a fallback provider for non-Swedish locations
When it happens
Trigger: SMHI returns an error JSON (e.g. quota or 404 body), a non-timeSeries product, empty/blocked response parsed as an object without timeSeries, or coordinates outside SMHI's coverage returning an unexpected body.
Common situations: Coordinates outside Sweden/SMHI coverage; SMHI API version change altering response shape; service outage; rate limiting.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid API response
- Latitude and longitude are required
- siteCode and provCode are required
- Unknown weather type: ${this.config.type}
- Latitude and longitude are required
AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31).
Data as JSON: /api/errors/50955b6a533fe252.
Report an issue: GitHub.