{"record":{"id":"50955b6a533fe252","repo":"MagicMirrorOrg/MagicMirror","slug":"invalid-weather-data","errorCode":null,"errorMessage":"Invalid weather data","messagePattern":"Invalid weather data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"defaultmodules/weather/providers/smhi.js","lineNumber":123,"sourceCode":"\t\t\t\t\tthis.onErrorCallback({\n\t\t\t\t\t\tmessage: \"Failed to parse API response\",\n\t\t\t\t\t\ttranslationKey: \"MODULE_ERROR_UNSPECIFIED\"\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tthis.fetcher.on(\"error\", (errorInfo) => {\n\t\t\tif (this.onErrorCallback) {\n\t\t\t\tthis.onErrorCallback(errorInfo);\n\t\t\t}\n\t\t});\n\t}\n\n\t#handleResponse (data) {\n\t\ttry {\n\t\t\tif (!data.timeSeries || !Array.isArray(data.timeSeries)) {\n\t\t\t\tthrow new Error(\"Invalid weather data\");\n\t\t\t}\n\n\t\t\tconst coordinates = this.#resolveCoordinates(data);\n\t\t\tlet weatherData;\n\n\t\t\tswitch (this.config.type) {\n\t\t\t\tcase \"current\":\n\t\t\t\t\tweatherData = this.#generateCurrentWeather(data.timeSeries, coordinates);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"forecast\":\n\t\t\t\tcase \"daily\":\n\t\t\t\t\tweatherData = this.#generateForecast(data.timeSeries, coordinates);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"hourly\":\n\t\t\t\t\tweatherData = this.#generateHourly(data.timeSeries, coordinates);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tLog.error(`[smhi] Unknown weather type: ${this.config.type}`);","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/MagicMirrorOrg/MagicMirror/blob/4b4a59534f7da01e4030e46029fe9dd649a7675e/defaultmodules/weather/providers/smhi.js#L105-L141","documentation":"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.","triggerScenarios":"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.","commonSituations":"Coordinates outside Sweden/SMHI coverage; SMHI API version change altering response shape; service outage; rate limiting.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"const looksLikeSmhiPayload = (d) => d != null && Array.isArray(d.timeSeries);\nif (!looksLikeSmhiPayload(data)) console.warn(\"SMHI payload missing timeSeries — check API URL/version and coverage\");","typeGuard":"const hasTimeSeries = (d) => typeof d === \"object\" && d !== null && Array.isArray(d.timeSeries);","tryCatchPattern":"provider.setCallbacks(\n  (data) => render(data),\n  (err) => { if (err.message === \"Invalid weather data\") fallbackProviderOrRetry(); }\n);","preventionTips":["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"],"tags":["api-response","smhi","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"4b4a59534f7da01e4030e46029fe9dd649a7675e","analyzedAt":"2026-08-31T21:49:42.591Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}