Skip to content
Snippets Groups Projects
Verified Commit 21fcf70e authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: make exeption messages more readable

parent 75565e53
Branches
Tags
No related merge requests found
...@@ -190,10 +190,12 @@ class Translations extends Base { ...@@ -190,10 +190,12 @@ class Translations extends Base {
/** /**
* Returns the translations for the current document. * Returns the translations for the current document.
* *
* @param element * @param {HTMLElement|undefined} [element] - Element to search for translations. Default: element with objectlink @schukai/monster/i18n/translations@@link.
* @returns {*} * @returns {Translations}
* @throws {Error} Element is not an HTMLElement * @throws {Error} Element is not an HTMLElement.
* @throws {Error} Missing translations * @throws {Error} Cannot find element with translations. Add a translations object to the document.
* @throws {Error} This element has no translations.
* @throws {Error} Missing translations.
*/ */
function getDocumentTranslations(element) { function getDocumentTranslations(element) {
...@@ -201,14 +203,17 @@ function getDocumentTranslations(element) { ...@@ -201,14 +203,17 @@ function getDocumentTranslations(element) {
if (!(element instanceof HTMLElement)) { if (!(element instanceof HTMLElement)) {
element = d.querySelector('['+ATTRIBUTE_OBJECTLINK+'~="' + translationsLinkSymbol.toString() + '"]'); element = d.querySelector('['+ATTRIBUTE_OBJECTLINK+'~="' + translationsLinkSymbol.toString() + '"]');
if (element === null) {
throw new Error("Cannot find element with translations. Add a translations object to the document.");
}
} }
if (!(element instanceof HTMLElement)) { if (!(element instanceof HTMLElement)) {
throw new Error("Element is not an HTMLElement"); throw new Error("Element is not an HTMLElement.");
} }
if (!hasObjectLink(element, translationsLinkSymbol)) { if (!hasObjectLink(element, translationsLinkSymbol)) {
throw new Error("Missing translations"); throw new Error("This element has no translations.");
} }
let obj = getLinkedObjects(element, translationsLinkSymbol); let obj = getLinkedObjects(element, translationsLinkSymbol);
...@@ -219,7 +224,7 @@ function getDocumentTranslations(element) { ...@@ -219,7 +224,7 @@ function getDocumentTranslations(element) {
} }
} }
throw new Error("Missing translations"); throw new Error("Missing translations.");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment