CICCIOSGAMINO / openweather-apis

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

handle errors in both methods getSmart and getData #41

Closed bayoudhi closed 3 years ago

bayoudhi commented 3 years ago

Fixes #40

Hi, I did this little PR to fix the callback of getSmartJSON

bayoudhi commented 3 years ago

Now when I run this code for example

weather.setAPPID('2a1ad423e9fad1a3ceda81fda56b1366');
weather.setLang('it');
weather.setUnits('metric');
weather.setCity('roma');

weather.getSmartJSON(function(err,smart){
    console.error(err);
});

I will get this output

Error: Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.
    at IncomingMessage.<anonymous> (/Users/hamza/Projects/openweather-apis/index.js:265:29)
    at IncomingMessage.emit (node:events:339:22)
    at endReadableNT (node:internal/streams/readable:1289:12)
    at processTicksAndRejections (node:internal/process/task_queues:80:21)