janl commented on code in PR #9177:
URL: https://github.com/apache/pouchdb/pull/9177#discussion_r2954850194


##########
packages/node_modules/pouchdb-abstract-mapreduce/src/index.js:
##########
@@ -358,15 +358,22 @@ function createAbstractMapReduce(localDocName, mapper, 
reducer, ddocValidator) {
     });
   }
 
-  function defaultsTo(value) {
-    return function (reason) {
+  // returns the awaited result of a promise or a property of that,
+  // or a default value if the promise throws a 404 error
+  async function defaultsTo(promise, value, prop) {
+    try {
+      const res = await promise;
+      if (res && prop in res) {
+        return res[prop];
+      } return res;
+    } catch (reason) {
       /* istanbul ignore else */
       if (reason.status === 404) {
         return value;
       } else {
         throw reason;
       }
-    };
+    }

Review Comment:
   🎨 let’s keep the `;`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to