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.

Solutions

  1. Verify the Buienradar endpoint URL is correct and reachable (curl it and inspect the body)
  2. Retry later — often a transient upstream outage
  3. Check this.onErrorCallback logs for the underlying fetch/parse error
  4. 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

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


AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31). Data as JSON: /api/errors/7e2079a3e525396f. Report an issue: GitHub.

Appendix: 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)