fixes of broken fucntions
This commit is contained in:
@@ -333,6 +333,9 @@ export default function Integration() {
|
||||
}
|
||||
|
||||
try {
|
||||
// fetchAPI extracts data from unified format {success: true, data: {...}}
|
||||
// But test endpoint may return {success: true, ...} directly (not wrapped)
|
||||
// So data could be either the extracted data object or the full response
|
||||
const data = await fetchAPI(`/v1/system/settings/integrations/${selectedIntegration}/test/`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
@@ -341,24 +344,51 @@ export default function Integration() {
|
||||
}),
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
toast.success(data.message || 'API connection test successful!');
|
||||
if (data.response) {
|
||||
toast.info(`Response: ${data.response}`);
|
||||
}
|
||||
if (data.tokens_used) {
|
||||
toast.info(`Tokens used: ${data.tokens_used}`);
|
||||
}
|
||||
|
||||
// Update validation status to success
|
||||
if (selectedIntegration) {
|
||||
setValidationStatuses(prev => ({
|
||||
...prev,
|
||||
[selectedIntegration]: 'success',
|
||||
}));
|
||||
// Handle both unified format (extracted) and direct format
|
||||
// If data has success field, it's the direct response (not extracted)
|
||||
// If data doesn't have success but has other fields, it's extracted data (successful)
|
||||
if (data && typeof data === 'object') {
|
||||
if (data.success === true || data.success === false) {
|
||||
// Direct response format (not extracted by fetchAPI)
|
||||
if (data.success) {
|
||||
toast.success(data.message || 'API connection test successful!');
|
||||
if (data.response) {
|
||||
toast.info(`Response: ${data.response}`);
|
||||
}
|
||||
if (data.tokens_used) {
|
||||
toast.info(`Tokens used: ${data.tokens_used}`);
|
||||
}
|
||||
|
||||
// Update validation status to success
|
||||
if (selectedIntegration) {
|
||||
setValidationStatuses(prev => ({
|
||||
...prev,
|
||||
[selectedIntegration]: 'success',
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
throw new Error(data.error || data.message || 'Connection test failed');
|
||||
}
|
||||
} else {
|
||||
// Extracted data format (successful response)
|
||||
toast.success('API connection test successful!');
|
||||
if (data.response) {
|
||||
toast.info(`Response: ${data.response}`);
|
||||
}
|
||||
if (data.tokens_used) {
|
||||
toast.info(`Tokens used: ${data.tokens_used}`);
|
||||
}
|
||||
|
||||
// Update validation status to success
|
||||
if (selectedIntegration) {
|
||||
setValidationStatuses(prev => ({
|
||||
...prev,
|
||||
[selectedIntegration]: 'success',
|
||||
}));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(data.error || 'Connection test failed');
|
||||
throw new Error('Invalid response format');
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Error testing connection:', error);
|
||||
|
||||
Reference in New Issue
Block a user