Skip to content

Commit 15dc7b3

Browse files
authored
Fix validation error of protocol not being returned (#843)
Fixes #830
1 parent bb168da commit 15dc7b3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/vapid-helper.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,20 @@ function validateSubject(subject) {
7575
+ 'mailto: address. ' + subject);
7676
}
7777

78+
let subjectParseResult = null;
7879
try {
79-
const subjectParseResult = new URL(subject);
80-
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {
81-
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
82-
}
83-
if (subjectParseResult.hostname === 'localhost') {
84-
console.warn('Vapid subject points to a localhost web URI, which is unsupported by '
85-
+ 'Apple\'s push notification server and will result in a BadJwtToken error when '
86-
+ 'sending notifications.');
87-
}
80+
subjectParseResult = new URL(subject);
8881
} catch (err) {
8982
throw new Error('Vapid subject is not a valid URL. ' + subject);
9083
}
84+
if (!['https:', 'mailto:'].includes(subjectParseResult.protocol)) {
85+
throw new Error('Vapid subject is not an https: or mailto: URL. ' + subject);
86+
}
87+
if (subjectParseResult.hostname === 'localhost') {
88+
console.warn('Vapid subject points to a localhost web URI, which is unsupported by '
89+
+ 'Apple\'s push notification server and will result in a BadJwtToken error when '
90+
+ 'sending notifications.');
91+
}
9192
}
9293

9394
function validatePublicKey(publicKey) {

0 commit comments

Comments
 (0)