Skip to content

Commit

Permalink
Re-throw all errors from send strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Brain committed Feb 14, 2019
1 parent 208c88b commit c78ba2c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/drivers/send/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */

import { isWindowClosed, getDomain, type CrossDomainWindowType, type DomainMatcher } from 'cross-domain-utils/src';
import { uniqueID } from 'belter/src';
import { uniqueID, stringifyError } from 'belter/src';

import { serializeMessage } from '../../serialize';
import type { Message } from '../types';
Expand All @@ -22,19 +22,18 @@ export function sendMessage(win : CrossDomainWindowType, domain : DomainMatcher,
}
}, { on, send });

let success = false;
let error;
const strategies = Object.keys(SEND_MESSAGE_STRATEGIES);
const errors = [];

for (const strategyName of Object.keys(SEND_MESSAGE_STRATEGIES)) {
for (const strategyName of strategies) {
try {
SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain);
success = true;
} catch (err) {
error = error || err;
errors.push(err);
}
}

if (!success) {
throw error;
if (errors.length === strategies.length) {
throw new Error(`All post-robot messaging strategies failed:\n\n${ errors.map(stringifyError).join('\n\n') }`);
}
}

0 comments on commit c78ba2c

Please # to comment.