Skip to content

Commit

Permalink
add level (info, warn, error) to error event
Browse files Browse the repository at this point in the history
  • Loading branch information
mnater committed Feb 4, 2019
1 parent d6f89c7 commit bee6c9a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 12 additions & 3 deletions Hyphenopoly.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@
registerOnCopy(el);
}
} else if (!H.clientFeat.langs[eLang]) {
H.events.dispatch("error", {"msg": "Element with '" + eLang + "' found, but '" + eLang + ".hpb' not loaded. Check language tags!"});
H.events.dispatch("error", {
"lvl": "warn",
"msg": "Element with '" + eLang + "' found, but '" + eLang + ".hpb' not loaded. Check language tags!"
});
}
/* eslint-enable security/detect-object-injection */
const cn = el.childNodes;
Expand Down Expand Up @@ -404,7 +407,10 @@
);
} else if (word.indexOf("-") === -1) {
if (word.length > 61) {
H.events.dispatch("error", {"msg": "found word longer than 61 characters"});
H.events.dispatch("error", {
"lvl": "warn",
"msg": "found word longer than 61 characters"
});
hw = word;
} else {
/* eslint-disable security/detect-object-injection */
Expand Down Expand Up @@ -577,7 +583,10 @@
hyphenate(lang, elo.selector, elo.element);
});
} else {
H.events.dispatch("error", {"msg": "engine for language '" + lang + "' loaded, but no elements found."});
H.events.dispatch("error", {
"lvl": "warn",
"msg": "engine for language '" + lang + "' loaded, but no elements found."
});
}
if (elements.counter[0] === 0) {
H.events.dispatch("hyphenopolyEnd");
Expand Down
18 changes: 15 additions & 3 deletions Hyphenopoly_Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,16 @@
define(
"error",
function def(e) {
window.console.error(e.msg);
switch (e.lvl) {
case "info":
window.console.info(e.msg);
break;
case "warn":
window.console.warn(e.msg);
break;
default:
window.console.error(e.msg);
}
},
true
);
Expand Down Expand Up @@ -215,7 +224,7 @@
);

/**
* Dispatch error <name> with arguments <data>
* Dispatch event <name> with arguments <data>
* @param {string} name The name of the event
* @param {Object|undefined} data Data of the event
* @returns {undefined}
Expand Down Expand Up @@ -259,7 +268,10 @@
} else {
H.events.dispatch(
"error",
{"msg": "unknown Event \"" + name + "\" discarded"}
{
"lvl": "warn",
"msg": "unknown Event \"" + name + "\" discarded"
}
);
}
}
Expand Down

0 comments on commit bee6c9a

Please sign in to comment.