Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit c78ba2c

Browse files
author
Daniel Brain
committed
Re-throw all errors from send strategies
1 parent 208c88b commit c78ba2c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/drivers/send/index.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

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

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

25-
let success = false;
26-
let error;
25+
const strategies = Object.keys(SEND_MESSAGE_STRATEGIES);
26+
const errors = [];
2727

28-
for (const strategyName of Object.keys(SEND_MESSAGE_STRATEGIES)) {
28+
for (const strategyName of strategies) {
2929
try {
3030
SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain);
31-
success = true;
3231
} catch (err) {
33-
error = error || err;
32+
errors.push(err);
3433
}
3534
}
3635

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

0 commit comments

Comments
 (0)