PokeAPI / pokedex-promise-v2

An easy way to use pokeapi v2 with promises in node.js
MIT License
510 stars 89 forks source link

.then is not a function #9

Closed designgears closed 8 years ago

designgears commented 8 years ago

I just started running into this today, if I call the function more than once it will throw this error. Any ideas what might be going on?

\pokedex.js:117 .then(function(response) { ^

TypeError: P.getPokemonByName(...).then is not a function at getPokemonType (C:\Users\user\Documents\project\mod\pokedex.js:117:5) at loadPokedex (C:\Users\user\Documents\project\mod\pokedex.js:52:6) at client. (C:\Users\user\Documents\project\mod\chat.js:25:6) at client.EventEmitter.emit (C:\Users\user\Documents\project\node_modules\tmi.js\lib\events.js:101:25) at client.EventEmitter.emits (C:\Users\user\Documents\project\node_modules\tmi.js\lib\events.js:64:19) at client.handleMessage (C:\Users\user\Documents\project\node_modules\tmi.js\lib\client.js:833:38) at parts.forEach (C:\Users\user\Documents\project\node_modules\tmi.js\lib\client.js:912:36) at Array.forEach (native) at client._onMessage (C:\Users\user\Documents\project\node_modules\tmi.js\lib\client.js:911:11) at WebSocket.onMessage (C:\Users\user\Documents\project\node_modules\ws\lib\WebSocket.js:418:14) at emitTwo (events.js:106:13) at WebSocket.emit (events.js:191:7) at Receiver.ontext (C:\Users\user\Documents\project\node_modules\ws\lib\WebSocket.js:816:10) at C:\Users\user\Documents\project\node_modules\ws\lib\Receiver.js:477:18 at Receiver.applyExtensions (C:\Users\user\Documents\project\node_modules\ws\lib\Receiver.js:364:5) at C:\Users\user\Documents\project\node_modules\ws\lib\Receiver.js:466:14

designgears commented 8 years ago

If I disable caching on the getJSON function everything works fine.

const cachedResult = cache.get(url);

to

const cachedResult = null;

It seems to only happen on getPokemonByName. getPokemonSpeciesByName and getEvolutionChainById don't have this issue from my limited testing.

Naramsim commented 8 years ago

Thanks @designgears for pointing it out. You are right. Caching right now does not work pretty well. It returns directly the result instead of a Promise with the result. That's why happens that error happens.

Could you please test this fork: https://github.com/karlbright/pokedex-promise-v2 I am pretty sure that does work. I'm only waiting for a pull request from that guy

Thanks

designgears commented 8 years ago

Testing that fork, everything seems to work as expected now!