Skip to content

Commit 54f035d

Browse files
committed
Adds in-HTML-body error reporting function
1 parent 2da59a8 commit 54f035d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

htmlpreview.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@
5858
.replace(/\/blob\//, '/').replace(/\/raw\//, '/');
5959
};
6060

61+
/**
62+
* Reports an error directly in HTML.
63+
* @param {string} msg - The error message to be reported to the user.
64+
* @returns {void}
65+
*/
66+
const reportError = function (msg) {
67+
const errP = document.createElement('p');
68+
errP.innerHTML = msg;
69+
document.body.appendChild(errP);
70+
throw new SyntaxError(msg);
71+
};
72+
6173
/**
6274
* If the first parameter is a URL to a file on a known git forge,
6375
* returns the URL to the raw version of this file
@@ -73,10 +85,7 @@
7385
const params = new URLSearchParams(location.search);
7486
const previewFileUrl = params.get('url');
7587
if (previewFileUrl === null) {
76-
const errP = document.createElement('p');
77-
errP.innerHTML = 'Please use "...?url=..." vs the old "...?..."!';
78-
document.body.appendChild(errP);
79-
throw new SyntaxError('Missing required parameter "url"!');
88+
reportError('Missing required parameter "url"');
8089
}
8190

8291
return rawifyForgeUrl(previewFileUrl);

0 commit comments

Comments
 (0)