Better log output to debug message Parsing
@@ -974,6 +974,15 @@ won.wonMessageFromJsonLd = function(wonMessageAsJsonLD) {
}
return wonMessage;
+ })
+ .catch(e => {
+ console.error(
+ "Error in wonMessageFromJsonLd: rawMessage: ",
+ wonMessageAsJsonLD,
+ " wonMessage: ",
+ wonMessage
+ );
+ rethrow(e);
});
});
};
@@ -2181,5 +2190,30 @@ won.MessageBuilder.prototype = {
},
};
+/**
+ * Optionally prepends a string, and then throws
+ * whatever it gets as proper javascript error.
+ * Note, that throwing an error will also
+ * reject in a `Promise`-constructor-callback.
+ * @param {*} e
+ * @param {*} prependedMsg
+ */
+function rethrow(e, prependedMsg = "") {
+ prependedMsg = prependedMsg ? prependedMsg + "\n" : "";
+
+ if (is("String", e)) {
+ throw new Error(prependedMsg + e);
+ } else if (e.stack && e.message) {
+ // a class defined
+ const g = new Error(prependedMsg + e.message);
+ g.stack = e.stack;
+ g.response = e.response; //we add the response so we can look up why a request threw an error
+
+ throw g;
+ } else {
+ throw new Error(prependedMsg + JSON.stringify(e));
+ }
+}
+
//TODO replace with `export default` after switching everything to ES6-module-syntax
export default won;
