diff --git a/src/log.js b/src/log.js index 108ef385219c..37a44ac552d9 100644 --- a/src/log.js +++ b/src/log.js @@ -49,6 +49,14 @@ export function isUserErrorMessage(message) { return message.indexOf(USER_ERROR_SENTINEL) >= 0; } +/** + * @param {string} message + * @return {string} The new message without USER_ERROR_SENTINEL + */ +export function stripUserError(message) { + return message.replace(USER_ERROR_SENTINEL, ''); +} + /** * @param {string} message * @return {boolean} Whether this message was a a user error from an iframe embed. diff --git a/src/service/viewer-impl.js b/src/service/viewer-impl.js index 2411e28a9c26..06c48fac82fe 100644 --- a/src/service/viewer-impl.js +++ b/src/service/viewer-impl.js @@ -19,7 +19,12 @@ import {Observable} from '../observable'; import {Services} from '../services'; import {ViewerInterface} from './viewer-interface'; import {VisibilityState} from '../visibility-state'; -import {dev, devAssert, duplicateErrorIfNecessary} from '../log'; +import { + dev, + devAssert, + duplicateErrorIfNecessary, + stripUserError, +} from '../log'; import {findIndex} from '../utils/array'; import { getSourceOrigin, @@ -856,17 +861,22 @@ export class ViewerImpl { } /** - * Creates an error for the case where a channel cannot be established. + * Creates a dev error for the case where a channel cannot be established. * @param {*=} opt_reason * @return {!Error} */ function getChannelError(opt_reason) { + let channelError; if (opt_reason instanceof Error) { opt_reason = duplicateErrorIfNecessary(opt_reason); opt_reason.message = 'No messaging channel: ' + opt_reason.message; - return opt_reason; + channelError = opt_reason; + } else { + channelError = new Error('No messaging channel: ' + opt_reason); } - return new Error('No messaging channel: ' + opt_reason); + // Force convert user error to dev error + channelError.message = stripUserError(channelError.message); + return channelError; } /**