Skip to content

Commit 4348b2a

Browse files
committed
fix: BYOK connection test - proper error handling for auth failures, structured error parsing, and improved error messages
1 parent 779d1b8 commit 4348b2a

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

backend/simpatico-ats.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7570,7 +7570,10 @@ async function handleBYOKValidate(request, env, ctx) {
75707570
return apiResponse({ connected: true, provider, models, total: models.length });
75717571

75727572
} catch (err) {
7573-
console.error(`[BYOK-Validate] Error: ${err.message}`);
7574-
return apiResponse({ connected: false, provider, error: `Connection failed: ${err.message}` });
7573+
console.error(`[BYOK-Validate] Error: ${err.name}: ${err.message}`, err.stack?.substring(0, 300));
7574+
const errMsg = err.message && err.message !== 'error'
7575+
? err.message
7576+
: `Could not reach ${body?.provider || 'provider'} API — check your API key and network`;
7577+
return apiResponse({ connected: false, provider: body?.provider, error: `Connection failed: ${errMsg}` });
75757578
}
75767579
}

dashboard/hr.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)