Skip to content

Commit 4349a25

Browse files
Improve error handling
1 parent 48c9439 commit 4349a25

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

tc-string-parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
var decodeString = function (bits) {
5353
var charOffset = "A".charCodeAt();
54-
var items = bits.match(/.{6}/g);
54+
var items = bits.match(/.{6}/g) || [];
5555
var result = "";
5656

5757
for (var index = 0, length = items.length; index < length; index += 1) {
@@ -93,7 +93,7 @@
9393

9494
var version = decodeInt(result[0].slice(0, 6));
9595
if (version !== 2) {
96-
throw new Error("Unsupported transparency and consent string version");
96+
throw new Error("Unsupported transparency and consent string version “" + version + "”");
9797
}
9898

9999
return result;

tc-string-parse.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ ava("empty string", (test) => {
1212

1313
ava("invalid string", (test) => {
1414
const error = test.throws(() => parse("!!!"));
15-
test.is(error.message, "Unsupported transparency and consent string version");
15+
test.is(error.message, "Unsupported transparency and consent string version “0”");
1616
});
1717

1818
ava("unsupported version", (test) => {
1919
const error = test.throws(() => parse("BOwxS1NOwxS1UAAAAAAADAAAAAAuiAAA"));
20-
test.is(error.message, "Unsupported transparency and consent string version");
20+
test.is(error.message, "Unsupported transparency and consent string version “1”");
2121
});
2222

2323
ava.before((test) => {

0 commit comments

Comments
 (0)