A
A
alexzsoda2021-09-05 08:55:37
Node.js
alexzsoda, 2021-09-05 08:55:37

How to handle TypeError: Cannot read property 'weather' of null?

I want the program to say 'you entered the wrong city' when naming a non-existent city in city.
How can I fix the code or handle the error so that it does not appear?

The code:

var weather = require('openweather-apis');
weather.setAPPID('TOKEN')
weather.setLang('ru')
weather.setUnits('metric')
let city = 'шцовлвлцщдй'
weather.setCity(city)
weather.getDescription(function(err, desc){
    console.log(desc)
});


Error:
/storage/bananjs/node_modules/openweather-apis/index.js:185
return callback(err, (jsonObj.weather)[0].description);
^

TypeError: Cannot read property 'weather' of null
at /storage/bananjs/node_modules/openweather-apis/index.js:185:37
at IncomingMessage. (/storage/bananjs/node_modules/openweather-apis/index.js:268:18)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2021-09-05
@alexzsoda

So I just opened this module on npm, and I immediately see:

New Version of the package (Node.js > 16) can be found at the new package domain @cicciosgamino/openweather-apis

So for starters, it’s worth trying to upgrade to another package
. In general, this is a jamb of the library, except for writing in issues , there’s nothing to be done

P
Pavel Shvedov, 2021-09-05
@mmmaaak

Check what you are requesting the weather property for null?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question