File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -301,22 +301,29 @@ function PhpbbWebpush() {
301301 } ) ;
302302
303303 const loadingIndicator = phpbb . loadingIndicator ( ) ;
304- fetch ( subscribeUrl , {
305- method : 'POST' ,
306- headers : {
307- 'X-Requested-With' : 'XMLHttpRequest' ,
308- } ,
309- body : getFormData ( newSubscription ) ,
310- } )
311- . then ( response => {
312- loadingIndicator . fadeOut ( phpbb . alertTime ) ;
313- return response . json ( ) ;
314- } )
315- . then ( handleSubscribe )
316- . catch ( error => {
317- loadingIndicator . fadeOut ( phpbb . alertTime ) ;
318- phpbb . alert ( ajaxErrorTitle , error ) ;
304+ try {
305+ const response = await fetch ( subscribeUrl , {
306+ method : 'POST' ,
307+ headers : {
308+ 'X-Requested-With' : 'XMLHttpRequest' ,
309+ } ,
310+ body : getFormData ( newSubscription ) ,
319311 } ) ;
312+ const data = await response . json ( ) ;
313+ loadingIndicator . fadeOut ( phpbb . alertTime ) ;
314+
315+ if ( data . success ) {
316+ handleSubscribe ( data ) ;
317+ } else {
318+ await newSubscription . unsubscribe ( ) ;
319+ promptDenied . set ( ) ;
320+ hidePopup ( document . getElementById ( 'wpn_popup_prompt' ) ) ;
321+ phpbb . alert ( ajaxErrorTitle , data . message || subscribeButton . getAttribute ( 'data-l-unsupported' ) ) ;
322+ }
323+ } catch ( error ) {
324+ loadingIndicator . fadeOut ( phpbb . alertTime ) ;
325+ phpbb . alert ( ajaxErrorTitle , error ) ;
326+ }
320327 } catch ( error ) {
321328 promptDenied . set ( ) ; // deny the prompt on error to prevent repeated prompting
322329 hidePopup ( document . getElementById ( 'wpn_popup_prompt' ) ) ;
You can’t perform that action at this time.
0 commit comments