Skip to content

Commit bb61ff5

Browse files
committed
Fix some leaky issues
1 parent 411a355 commit bb61ff5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

styles/all/template/webpush.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,20 @@ function PhpbbWebpush() {
315315
if (data.success) {
316316
handleSubscribe(data);
317317
} else {
318-
await newSubscription.unsubscribe();
318+
// Server rejected the subscription; clean up the browser-side subscription
319+
// without awaiting, so a failure here can't bubble to the outer catch and
320+
// incorrectly trigger promptDenied or show the wrong error message.
321+
newSubscription.unsubscribe().catch(console.error);
319322
promptDenied.set();
320323
hidePopup(document.getElementById('wpn_popup_prompt'));
321324
phpbb.alert(ajaxErrorTitle, data.message || subscribeButton.getAttribute('data-l-unsupported'));
322325
}
323326
} catch (error) {
324327
loadingIndicator.fadeOut(phpbb.alertTime);
325-
phpbb.alert(ajaxErrorTitle, error);
328+
// Clean up the browser-side subscription so it doesn't become orphaned
329+
// when the server request fails (network error, bad JSON, etc.).
330+
newSubscription.unsubscribe().catch(console.error);
331+
phpbb.alert(ajaxErrorTitle, error.message || subscribeButton.getAttribute('data-l-unsupported'));
326332
}
327333
} catch (error) {
328334
promptDenied.set(); // deny the prompt on error to prevent repeated prompting

0 commit comments

Comments
 (0)