MagicMirrorOrg/MagicMirror · error · Error
Invalid API response
Error message
Invalid API response
What it means
#parseResponse validates the shape of the JSON returned by the WeatherAPI.com API. A valid response must contain location, current, forecast, and forecast.forecastday as an array. If any is absent the provider considers the payload unusable and throws "Invalid API response".
Source
Thrown at defaultmodules/weather/providers/weatherapi.js:212
const locationParts = [
responseData.location.name,
responseData.location.region,
responseData.location.country
]
.map((value) => `${value}`.trim())
.filter((value) => value !== "");
if (locationParts.length > 0) {
this.locationName = locationParts.join(", ").trim();
}
if (
!responseData.location
|| !responseData.current
|| !responseData.forecast
|| !Array.isArray(responseData.forecast.forecastday)
) {
throw new Error("Invalid API response");
}
return responseData;
}
#parseSunDatetime (forecastDay, key) {
const timeValue = forecastDay?.astro?.[key];
if (!timeValue || !forecastDay?.date) {
return null;
}
const match = (/^\s*(\d{1,2}):(\d{2})\s*(AM|PM)\s*$/i).exec(timeValue);
if (!match) {
return null;
}
let hour = parseInt(match[1], 10);
const minute = parseInt(match[2], 10);View on GitHub (pinned to 4b4a59534f)
Solutions
- Log the raw response body around the throw to see the API's error message (usually an "error" object with code/message).
- Check your weatherapi.com dashboard for quota/plan limits and key status.
- Test the same request URL in a browser/curl to confirm the API response shape.
- Ensure no proxy or ad-blocker is rewriting API responses; verify network egress.
- If your plan lacks forecast data, upgrade or switch config.type to "current".
Example fix
// before — silent failure hides the API error body
throw new Error("Invalid API response");
// after — surface it
if (!responseData.location || !responseData.current || !responseData.forecast) {
throw new Error(`Invalid API response: ${JSON.stringify(responseData).slice(0, 200)}`);
} Defensive patterns
Strategy: try-catch
Validate before calling
const ok = (d) => d && d.location && d.current && d.forecast && Array.isArray(d.forecast.forecastday);
// call the API directly first if you suspect plan/quota issues:
// fetch(`https://api.weatherapi.com/v1/forecast.json?key=${key}&q=${lat},${lon}&days=3`) Type guard
function isWeatherApiResponse(d) {
return !!d && typeof d === "object"
&& !!d.location && !!d.current && !!d.forecast
&& Array.isArray(d.forecast.forecastday);
} Try / catch
try {
await provider.initialize();
} catch (err) {
if (err.message === "Invalid API response") {
Log.error("weatherapi returned an unexpected body — check key status/quota at weatherapi.com");
showFallbackWeather();
} else { throw err; }
} Prevention
- Monitor your weatherapi.com quota; free tier is 1M calls/month with per-hour caps.
- Cache responses and lengthen updateInterval to reduce quota burn.
- Alert on the API's own error body (error.code) rather than only on shape failures.
When it happens
Trigger: The API returns 200 with an error JSON body (invalid/expired key, quota exceeded, bad query), a partially empty payload, or a non-standard body (proxy/captive-portal HTML parsed oddly, cached error).
Common situations: Free-tier daily quota exhausted; key not yet activated (weatherapi keys need a trial activation); plan downgraded removing forecast access; corporate proxy intercepting requests.
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 grid point data
- Failed to fetch grid point: HTTP ${pointsResponse.status}
- Invalid current weather data
- Failed to fetch observation stations: HTTP ${stationsRespons
- No observation stations found
AI-assisted analysis of MagicMirrorOrg/MagicMirror@4b4a59534f (2026-08-31).
Data as JSON: /api/errors/aaead26038ed298c.
Report an issue: GitHub.