@@ -1891,6 +1891,25 @@ <h4>Multi-Platform Job Syndication</h4>
18911891 } ) ;
18921892
18931893 const result = await res . json ( ) ;
1894+
1895+ // Handle HTTP-level errors (auth, validation, server errors)
1896+ if ( ! res . ok ) {
1897+ // Worker returns { success: false, error: { code, message } }
1898+ const errMsg = result ?. error ?. message || result ?. error || `Server error (${ res . status } )` ;
1899+ const errCode = result ?. error ?. code || '' ;
1900+ statusDiv . style . background = '#fef2f2' ;
1901+ statusDiv . style . border = '1px solid #fecaca' ;
1902+ statusDiv . style . color = '#991b1b' ;
1903+ if ( res . status === 401 || errCode === 'AUTH_ERROR' ) {
1904+ statusDiv . innerHTML = '<i class="fas fa-lock" style="font-size:16px;"></i> <span>Authentication required — please log in again</span>' ;
1905+ } else if ( res . status === 403 ) {
1906+ statusDiv . innerHTML = '<i class="fas fa-ban" style="font-size:16px;"></i> <span>Permission denied — admin access required</span>' ;
1907+ } else {
1908+ statusDiv . innerHTML = '<i class="fas fa-times-circle" style="font-size:16px;"></i> <span>' + ( typeof errMsg === 'string' ? errMsg : JSON . stringify ( errMsg ) ) + '</span>' ;
1909+ }
1910+ return ;
1911+ }
1912+
18941913 const data = result . data || result ;
18951914
18961915 if ( data . connected ) {
@@ -1967,11 +1986,12 @@ <h4>Multi-Platform Job Syndication</h4>
19671986 statusDiv . innerHTML += '<br><span style="font-weight:400;font-size:12px;">' + data . message + '</span>' ;
19681987 }
19691988 } else {
1970- // FAILED — show red badge
1989+ // FAILED — show red badge with proper error extraction
1990+ const errDetail = typeof data . error === 'object' ? ( data . error . message || JSON . stringify ( data . error ) ) : ( data . error || 'Unknown error' ) ;
19711991 statusDiv . style . background = '#fef2f2' ;
19721992 statusDiv . style . border = '1px solid #fecaca' ;
19731993 statusDiv . style . color = '#991b1b' ;
1974- statusDiv . innerHTML = '<i class="fas fa-times-circle" style="font-size:16px;"></i> <span>Connection Failed: ' + ( data . error || 'Unknown error' ) + '</span>' ;
1994+ statusDiv . innerHTML = '<i class="fas fa-times-circle" style="font-size:16px;"></i> <span>Connection Failed: ' + errDetail + '</span>' ;
19751995 }
19761996 } catch ( err ) {
19771997 statusDiv . style . background = '#fef2f2' ;
0 commit comments