Better Logging for wonMessageFromJsonLd function (debug errors and debug forwardedMessages)
@@ -914,15 +914,43 @@ won.wonMessageFromJsonLd = async function(wonMessageAsJsonLD) {
const expandedJsonLd = await jsonld.promises.expand(wonMessageAsJsonLD);
const wonMessage = new WonMessage(expandedJsonLd);
- if (wonMessage.parseErrors && wonMessage.parseErrors.length > 0) {
- console.warn("wonMessage ParseError: " + wonMessage.parseErrors);
- }
-
await wonMessage.frameInPromise();
await wonMessage.generateContentGraphTrig();
await wonMessage.generateCompactedFramedMessage();
await wonMessage.generateContainedForwardedWonMessages();
+ if (wonMessage.hasParseErrors() && !wonMessage.isResponse()) {
+ console.warn(
+ "wonMessage<",
+ wonMessage.getMessageUri(),
+ "> msgType<",
+ wonMessage.getMessageType(),
+ "> ParseError: {" + wonMessage.parseErrors,
+ "} wonMessage: ",
+ wonMessage
+ );
+ }
+ if (wonMessage.hasContainedForwardedWonMessages()) {
+ console.debug(
+ "wonMessage<",
+ wonMessage.getMessageUri(),
+ "> msgType<",
+ wonMessage.getMessageType(),
+ "> contains forwardedMessages wonMessage: ",
+ wonMessage
+ );
+ wonMessage.getContainedForwardedWonMessages().map(forwardedWonMessage => {
+ console.debug(
+ "-- forwardedMessage<",
+ forwardedWonMessage.getMessageUri(),
+ "> msgType<",
+ forwardedWonMessage.getMessageType(),
+ ">, forwardedWonMessage: ",
+ forwardedWonMessage
+ );
+ });
+ }
+
return wonMessage;
};
@@ -1200,9 +1228,8 @@ WonMessage.prototype = {
return Promise.resolve(this.containedForwardedWonMessages);
} else if (forwardedMessageUris) {
- console.warn(
- "WonMessage contains more than one forwardedMessage on the same level: omitting forwardMessages, wonMessage:",
- this
+ this.parseErrors.push(
+ "WonMessage contains more than one forwardedMessage on the same level: omitting forwardMessages"
);
return Promise.resolve(this.containedForwardedWonMessages);
} else {
@@ -1452,6 +1479,9 @@ WonMessage.prototype = {
this.containedForwardedWonMessages.length > 0
);
},
+ hasParseErrors: function() {
+ return this.parseErrors && this.parseErrors.length > 0;
+ },
getContainedForwardedWonMessages: function() {
return this.containedForwardedWonMessages;
},
