davidlivingrooms/OpenMicNightScraper

code hint

Closed this issue · 4 comments

from here: https://github.com/GrumpyPants/OpenMicNightScraper/blob/a1ce26992a51b013dae3a52796d6b2b9c38de705/index.js#L218

db.none(updateStatement, [nameVenueObject.venueName, streetAddress])

Calling something like this and not using the returned value creates a loose promise object. If the operation rejects, the promise library will throw an exception that says uncaught exception, no .catch provided ;)

Happy New Year! :)

Happy New Year!

So I wasn't expecting any return values since this is an update statement. Is .none() not the method I want to use here? I do have a .catch but on the parent promise

https://github.com/GrumpyPants/OpenMicNightScraper/blob/a1ce26992a51b013dae3a52796d6b2b9c38de705/index.js#L271

Would it be better to also place a catch on this promise as well? I thought that if the inner promise failed it would 'bubble' up to the parent promise .catch and could be handled there. Thank you very much for your time and for looking at this!

Promise architecture is based on chaining requests. Your code example breaks the chain, resulting in a loose promise. You need to chain the result into the common output according to the business logic of what it is you doing there ;)

It doesn't matter which database requests you are using there. In fact, the database got nothing to do with the problem. The problem is with the promise misuse there.

I've added a .catch to that .none call to avoid the exception. Thanks again.

Happy New Year! :)