Browse Source

chore: improve/guard function if invalid paameter is given

rugk 4 tháng trước cách đây
mục cha
commit
0de2b52550
1 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 5 0
      js/privatebin.js

+ 5 - 0
js/privatebin.js

@@ -1750,6 +1750,11 @@ window.PrivateBin = (function () {
                 args = [args.message];
             }
 
+            // function guard
+            if (!element) {
+                throw new TypeError(`invalid/no element (${element}) given for alert type ${alertType[id]} with ID ${id}`);
+            }
+
             // pass to custom handler if defined
             if (typeof customHandler === 'function') {
                 let handlerResult = customHandler(alertType[id], element, args, icon);