« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/aggregate.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/aggregate.js')
-rw-r--r--src/util/aggregate.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/util/aggregate.js b/src/util/aggregate.js
index 2e4d9de..5429e64 100644
--- a/src/util/aggregate.js
+++ b/src/util/aggregate.js
@@ -93,10 +93,27 @@ export function openAggregate({
 
   aggregate.receive = (results) => {
     if (!Array.isArray(results)) {
-      throw new Error(`Expected an array`);
+      if (typeof results === 'object' && results.aggregate) {
+        const {aggregate, result} = results;
+
+        try {
+          aggregate.close();
+        } catch (error) {
+          errors.push(error);
+        }
+
+        return result;
+      }
+
+      throw new Error(`Expected an array or {aggregate, result} object`);
     }
 
     return results.map(({aggregate, result}) => {
+      if (!aggregate) {
+        console.log('nope:', results);
+        throw new Error(`Expected an array of {aggregate, result} objects`);
+      }
+
       try {
         aggregate.close();
       } catch (error) {