I really don't know what's going on, but if I write
return db.many(query, userid, (rows, error) => { return new Promise((resolve, reject) => { if (rows) { resolve(rows) } else { error.received == 0 ? resolve(0) : reject(error) } }) })
I don't get the results I want, but
return db.many(query, userid) .then(rows => { return new Promise((resolve) => { resolve(rows) }) }) .catch(error => { return new Promise((resolve, reject) => { error.received == 0 ? resolve(0) : reject(error) }) })
does give me the results I want!
The goal is to resolve to 0 if no data was returned, resolve the rows, or reject the error that isn't No data returned .
What is actually happening in the first code block is that the error is not being processed, and is just being returned as is, and I'm getting No data was returned error.
At first, I thought it was a .many() method that didn't have a callback ability, but even .one() has the same problem (I'm recreating a situation where no data will be returned.…