CICCIOSGAMINO / openweather-apis

Simple APIs for OpenWeatherMap.org basic services
GNU General Public License v3.0
44 stars 27 forks source link

The callback function of weather.getSmartJSON is not working at all #40

Closed bayoudhi closed 3 years ago

bayoudhi commented 3 years ago

Hello, I really like this module, especially how it's developed to be used directly in weather applications (based on the user's current city). However, I detected a problem when calling getSmartJSON

The callback function in method getSmartJSON is not working correctly --> neither the err object nor the smart object is returned, and I get this error when I run this code or even when I run the example.js code:

var weather = require('./index.js');

weather.setAPPID('2a1ad423e9fad1a3ceda81fda56b1366');
weather.setLang('it');
weather.setUnits('metric');
weather.setCity('roma');
// weather.setCoordinate(41.9152,12.5068)

weather.getSmartJSON(function(err,smart){

});

The error

/Users/abc/Projects/openweather-apis/index.js:192
      smartJSON.temp = jsonObj.main.temp;

TypeError: Cannot read property 'temp' of undefined
    at /Users/abc/Projects/openweather-apis/index.js:192:37
    at IncomingMessage.<anonymous> (/Users/abc/Projects/openweather-apis/index.js:265:18)
    at IncomingMessage.emit (node:events:339:22)
    at endReadableNT (node:internal/streams/readable:1289:12)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)

This is a bug, I think that the function behind the callback is throwing an error rather than returning an error or a result.