MagicMirrorOrg/MagicMirror · error · Error
Invalid API response
Error message
Invalid API response
What it means
buienradar's #handleResponse validates the parsed API payload and expects an object with a non-empty `days` array. If the response is shaped differently (missing days, empty array, or non-object), it throws 'Invalid API response'. This guards against unexpected upstream data before processing weather entries.
Source
Thrown at defaultmodules/weather/providers/buienradar.js:134
const data = await response.json();
this.#handleResponse(data);
} catch (error) {
Log.error("[buienradar] Failed to parse JSON:", error);
this.#sendErrorCallback("Failed to parse API response");
}
});
this.fetcher.on("error", (errorInfo) => {
if (this.onErrorCallback) {
this.onErrorCallback(errorInfo);
}
});
}
#handleResponse (data) {
try {
if (!Array.isArray(data?.days) || data.days.length === 0) {
throw new Error("Invalid API response");
}
this.#setLocationName(data.location);
let weatherData;
switch (this.config.type) {
case "current":
weatherData = this.#generateCurrentWeather(data.days[0]);
break;
case "forecast":
case "daily":
weatherData = this.#generateDailyForecast(data.days);
break;
case "hourly":
weatherData = this.#generateHourlyForecast(data.days);
break;
default:
throw new Error(`Unknown weather type: ${this.config.type}`);View on GitHub (pinned to 4b4a59534f)
Solutions
- Verify the Buienradar endpoint URL is correct and reachable (curl it and inspect the body)
- Retry later — often a transient upstream outage
- Check this.onErrorCallback logs for the underlying fetch/parse error
- Upgrade the module if the Buienradar API schema changed
Defensive patterns
Strategy: type-guard
Validate before calling
const looksLikeBuienradarPayload = (d) => d != null && Array.isArray(d.days) && d.days.length > 0;
if (!looksLikeBuienradarPayload(data)) console.warn("Buienradar payload malformed; will surface provider error"); Type guard
const hasDays = (d) => typeof d === "object" && d !== null && Array.isArray(d.days) && d.days.length > 0;
Try / catch
provider.setCallbacks(
(data) => render(data),
(err) => { if (err.message === "Invalid API response") scheduleRetryWithBackoff(); }
); Prevention
- Monitor buienradar.nl status; expect transient outages
- Log raw response bodies on error to detect HTML/proxy interlopers
- Pin/review the module version when the upstream API schema changes
- Handle the provider's onError callback with a retry/fallback provider
When it happens
Trigger: Buienradar API returns an HTML error page, an error JSON object without a `days` array, or an empty days array; JSON parsing produced something without the expected shape.
Common situations: Buienradar service outage or maintenance; network middleware (proxy/captive portal) returning HTML; API schema change; rate limiting returning an error body.
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 weather data
- Latitude and longitude are required
- Unknown weather type: ${this.config.type}
- siteCode and provCode are required
- Unknown weather type: ${this.config.type}
AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31).
Data as JSON: /api/errors/7e2079a3e525396f.
Report an issue: GitHub.