fix: 修复 AI 测试链接返回连接失败的问题
- 修复 AJAX 函数中缺少 api_id 参数检查导致的错误 - 统一错误消息格式,使用数组包装错误信息 - 修复 JavaScript 中错误消息解析逻辑 - 改进错误提示的可读性和调试信息
This commit is contained in:
@@ -8787,15 +8787,21 @@ function argon_ajax_test_unified_api() {
|
||||
check_ajax_referer('argon_test_unified_api', 'nonce');
|
||||
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error('权限不足');
|
||||
wp_send_json_error(['message' => '权限不足']);
|
||||
return;
|
||||
}
|
||||
|
||||
$api_id = isset($_POST['api_id']) ? sanitize_text_field($_POST['api_id']) : '';
|
||||
|
||||
if (empty($api_id)) {
|
||||
wp_send_json_error(['message' => '缺少 API ID 参数']);
|
||||
return;
|
||||
}
|
||||
|
||||
$api_id = sanitize_text_field($_POST['api_id']);
|
||||
$api = argon_get_api_by_id($api_id);
|
||||
|
||||
if (!$api) {
|
||||
wp_send_json_error('API 不存在');
|
||||
wp_send_json_error(['message' => 'API 不存在']);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8816,7 +8822,7 @@ function argon_ajax_test_unified_api() {
|
||||
$api_endpoint = !empty($api['api_endpoint']) ? $api['api_endpoint'] : (isset($default_endpoints[$api['provider']]) ? $default_endpoints[$api['provider']] : '');
|
||||
|
||||
if (empty($api_endpoint)) {
|
||||
wp_send_json_error('未配置 API 端点');
|
||||
wp_send_json_error(['message' => '未配置 API 端点']);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8865,7 +8871,7 @@ function argon_ajax_test_unified_api() {
|
||||
$response_time = round((microtime(true) - $start_time) * 1000);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
wp_send_json_error('连接失败: ' . $response->get_error_message());
|
||||
wp_send_json_error(['message' => '连接失败: ' . $response->get_error_message()]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8880,7 +8886,7 @@ function argon_ajax_test_unified_api() {
|
||||
'response_time' => $response_time
|
||||
]);
|
||||
} else {
|
||||
wp_send_json_error('API 返回格式异常: ' . substr($body, 0, 200));
|
||||
wp_send_json_error(['message' => 'API 返回格式异常: ' . substr($body, 0, 200)]);
|
||||
}
|
||||
} else {
|
||||
$error_msg = 'HTTP ' . $status_code;
|
||||
@@ -8890,7 +8896,7 @@ function argon_ajax_test_unified_api() {
|
||||
} else {
|
||||
$error_msg .= ': ' . substr($body, 0, 200);
|
||||
}
|
||||
wp_send_json_error($error_msg);
|
||||
wp_send_json_error(['message' => $error_msg]);
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_argon_test_unified_api', 'argon_ajax_test_unified_api');
|
||||
|
||||
@@ -2455,8 +2455,8 @@ function themeoptions_page(){
|
||||
if (response.success) {
|
||||
alert('✓ ' + response.data.message);
|
||||
} else {
|
||||
// wp_send_json_error 的错误消息在 response.data 中
|
||||
let errorMsg = response.data || '<?php _e('未知错误', 'argon'); ?>';
|
||||
// wp_send_json_error 的错误消息在 response.data.message 中
|
||||
let errorMsg = (response.data && response.data.message) ? response.data.message : '<?php _e('未知错误', 'argon'); ?>';
|
||||
alert('✗ <?php _e('测试失败:', 'argon'); ?> ' + errorMsg);
|
||||
}
|
||||
$btn.prop('disabled', false).html(originalHtml);
|
||||
@@ -2464,7 +2464,7 @@ function themeoptions_page(){
|
||||
// AJAX 请求本身失败
|
||||
console.error('AJAX Error:', xhr, status, error);
|
||||
console.error('Response Text:', xhr.responseText);
|
||||
alert('<?php _e('请求失败,请重试', 'argon'); ?>');
|
||||
alert('✗ <?php _e('请求失败:', 'argon'); ?> ' + (xhr.responseText || error || '<?php _e('网络错误', 'argon'); ?>'));
|
||||
$btn.prop('disabled', false).html(originalHtml);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user