diff --git a/src/drivers/send/index.js b/src/drivers/send/index.js index 2943cdff..50f41426 100644 --- a/src/drivers/send/index.js +++ b/src/drivers/send/index.js @@ -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'; @@ -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') }`); } }