Skip to content

Conversation

@superdav42
Copy link
Collaborator

@superdav42 superdav42 commented Dec 13, 2025

Summary

This PR significantly improves the error handling and debugging capabilities of the Enhance Control Panel integration, making it much easier to diagnose and troubleshoot API connection issues.

Problem

Issue #290 reported that users were getting a generic "Failed to connect to Enhance API" error message with no additional context about what was actually failing. This made it very difficult to troubleshoot connection issues.

Changes

Enhanced test_connection() method:

  • ✅ Provides detailed error messages based on HTTP status codes (401, 403, 404, 500+)
  • ✅ Includes specific troubleshooting guidance for each error type
  • ✅ Adds comprehensive logging for successful and failed tests
  • ✅ Parses and displays error messages from API response body
  • ✅ Provides a checklist of configuration items to verify

Improved on_add_domain() method:

  • ✅ Enhanced logging with SUCCESS/ERROR/WARNING prefixes for clarity
  • ✅ Includes HTTP status code in error messages
  • ✅ Provides troubleshooting guidance for specific error codes
  • ✅ Logs successful domain additions with domain ID
  • ✅ Better handling of unclear API responses

Better on_remove_domain() method:

  • ✅ Improved error handling when listing domains fails
  • ✅ Enhanced logging throughout the removal process
  • ✅ Better success/failure detection and reporting
  • ✅ More descriptive messages for each removal step

Benefits

  1. Better User Experience: Users can now see exactly what's failing and get actionable steps to fix it
  2. Reduced Support Burden: Error messages include troubleshooting guidance, helping users self-diagnose issues
  3. Easier Debugging: Structured logs with SUCCESS/ERROR/WARNING prefixes make issues easier to identify
  4. More Context: HTTP status codes and API messages provide complete error context

Example Error Message

Before:

Failed to connect to Enhance API

After:

Failed to connect to Enhance API: HTTP Status: 401 Authentication failed. 
Please verify your API token is correct and has not expired. Please check: 
1. API URL includes /api/ at the end (e.g., https://panel.example.com/api/) 
2. API token is valid and has System Administrator role 
3. Server ID matches a server in your Enhance panel 
4. Your WordPress server can reach the Enhance panel

Testing

  • ✅ All code passes PHPCS code style checks
  • ✅ All code passes PHPStan static analysis
  • ✅ No regressions in existing functionality
  • ✅ Error messages are clear and actionable

Closes

Closes #290

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling and logging for Enhance host provider integration, providing clearer error messages with actionable troubleshooting steps for domain operations, connection testing, and configuration issues.

✏️ Tip: You can customize this high-level summary in your review settings.

Enhanced error handling and logging in the Enhance Control Panel integration
to provide better diagnostics when API connection issues occur.

Changes to test_connection() method:
- Added detailed error messages based on HTTP status codes (401, 403, 404, 500+)
- Included specific troubleshooting guidance for common issues
- Added logging for successful and failed connection tests
- Parse and display API error messages from response body
- Provide checklist of configuration items to verify

Changes to on_add_domain() method:
- Enhanced logging with SUCCESS/ERROR/WARNING prefixes
- Added HTTP status code to error messages
- Included troubleshooting guidance for specific error codes
- Log successful domain additions with domain ID
- Better handling of unclear responses

Changes to on_remove_domain() method:
- Improved error handling when listing domains fails
- Enhanced logging throughout the removal process
- Better success/failure detection and reporting
- More descriptive messages for each step

Benefits:
- Users can now see exactly what's failing in the API connection
- Error messages provide actionable troubleshooting steps
- Logs are more structured and easier to read (SUCCESS/ERROR/WARNING)
- Reduces support requests by helping users self-diagnose issues
- Makes debugging Enhance integration issues much easier

Closes #290

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2025

Walkthrough

The PR improves error handling and logging in the Enhance host-provider integration, providing explicit guidance when configuration is missing, including domain IDs in success messages, adding HTTP context to error messages, implementing pre-checks for domain operations, and enhancing connection test feedback with actionable troubleshooting steps.

Changes

Cohort / File(s) Summary
Enhance integration error handling & logging
inc/integrations/host-providers/class-enhance-host-provider.php
Added detailed, user-facing error messages and logging throughout the Enhance integration: server ID configuration guidance, domain operation feedback with domain IDs and HTTP context, pre-check validation for domain listing before removal attempts, and enhanced connection test responses with troubleshooting guidance for common HTTP status codes (401, 403, 404, 409) and configuration issues.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Areas requiring attention:

  • Validation of error message accuracy for each HTTP status code (401, 403, 404, 409) and their recommended troubleshooting steps
  • Confirmation that pre-check for domain listing failure properly prevents deletion attempts and provides clear feedback
  • Review of domain ID extraction and logging logic to ensure consistency across addition, removal, and listing operations
  • Verification that the connection test messaging covers all documented API response scenarios

Possibly related PRs

  • ultimate-multisite#267: Directly modifies the same Enhance host-provider class file with related improvements to the integration.

Poem

🐰 Enhance logs now tell the tale,
With error codes that never fail!
Clear guidance flows for every plight,
Domain IDs and HTTP might,
Connection tests shine crystal-bright! 🔌✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve Enhance API integration error handling and debugging' is a concise, specific description of the main changes in the PR, which focuses on enhanced error messages and debugging capabilities for the Enhance integration.
Linked Issues check ✅ Passed The PR addresses issue #290 by implementing detailed error handling, structured logging, HTTP status-based messaging, and troubleshooting guidance that transform generic 'connection-failed' errors into actionable diagnostics for users.
Out of Scope Changes check ✅ Passed All changes are scoped to improving error handling and logging in the Enhance integration; no unrelated code modifications, feature additions outside the debugging scope, or alterations to public APIs were introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/enhance-api-error-messages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
inc/integrations/host-providers/class-enhance-host-provider.php (1)

147-174: Good improvements to error handling and user guidance.

The addition of domain ID to success messages, HTTP status codes to errors, and specific troubleshooting guidance for common failure scenarios directly addresses the PR objectives.

Consider using the $log_level parameter of wu_log_add() instead of string prefixes:

-wu_log_add('integration-enhance', 'ERROR: Failed to add domain...', ...);
+wu_log_add('integration-enhance', 'Failed to add domain...', \Psr\Log\LogLevel::ERROR);

This would enable log filtering and is more semantically correct. Based on the helper function signature in inc/functions/helper.php.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8490fd0 and d97b5fe.

📒 Files selected for processing (1)
  • inc/integrations/host-providers/class-enhance-host-provider.php (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
inc/integrations/host-providers/class-enhance-host-provider.php (1)
inc/functions/helper.php (1)
  • wu_log_add (208-211)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: PHP 7.4
  • GitHub Check: cypress (8.2, chrome)
  • GitHub Check: cypress (8.1, chrome)
  • GitHub Check: Build Plugin for Testing
🔇 Additional comments (4)
inc/integrations/host-providers/class-enhance-host-provider.php (4)

132-132: LGTM: Clear configuration guidance.

The enhanced error message explicitly tells users to define WU_ENHANCE_SERVER_ID in wp-config.php, which directly addresses the issue reported in #290.


192-205: LGTM: Fail-fast approach for domain removal.

The pre-check at lines 202-205 that bails early if listing domains fails is good defensive programming. It prevents unnecessary deletion attempts when the API is unreachable.


219-237: LGTM: Comprehensive deletion result handling.

The improved logging covers all three scenarios (success, error, and unclear response), and the warning at line 219 is particularly helpful for users who might attempt to remove an already-deleted domain.


285-301: The file referenced in this review comment could not be located in the repository. Without access to the actual code and the Enhance API documentation, the validity of the concern about success detection criteria cannot be verified.

Comment on lines +304 to 356
wu_log_add('integration-enhance', sprintf('Connection test failed. Response: %s', wp_json_encode($response)));

// Build detailed error message
$error_message = __('Failed to connect to Enhance API', 'ultimate-multisite');
$error_details = [];

if (isset($response['error'])) {
$error_details[] = $response['error'];
}

if (isset($response['response_code'])) {
// translators: %d is the HTTP status code number
$error_details[] = sprintf(__('HTTP Status: %d', 'ultimate-multisite'), $response['response_code']);

// Provide specific guidance based on status code
switch ($response['response_code']) {
case 401:
$error_details[] = __('Authentication failed. Please verify your API token is correct and has not expired.', 'ultimate-multisite');
break;
case 403:
$error_details[] = __('Access forbidden. Please ensure your API token has the System Administrator role.', 'ultimate-multisite');
break;
case 404:
$error_details[] = __('Server not found. Please verify your Server ID is correct.', 'ultimate-multisite');
break;
case 500:
case 502:
case 503:
$error_details[] = __('Enhance server error. Please check your Enhance Control Panel status.', 'ultimate-multisite');
break;
}
}

if (isset($response['response_body'])) {
$error_body = json_decode($response['response_body'], true);
if (json_last_error() === JSON_ERROR_NONE && isset($error_body['message'])) {
// translators: %s is the error message from the Enhance API
$error_details[] = sprintf(__('API Message: %s', 'ultimate-multisite'), $error_body['message']);
}
}

// Add troubleshooting tips
$error_details[] = __('Please check:', 'ultimate-multisite');
$error_details[] = __('1. API URL includes /api/ at the end (e.g., https://panel.example.com/api/)', 'ultimate-multisite');
$error_details[] = __('2. API token is valid and has System Administrator role', 'ultimate-multisite');
$error_details[] = __('3. Server ID matches a server in your Enhance panel', 'ultimate-multisite');
$error_details[] = __('4. Your WordPress server can reach the Enhance panel', 'ultimate-multisite');

$error_message .= ': ' . implode(' ', $error_details);

$error = new \WP_Error('connection-failed', $error_message);
wp_send_json_error($error);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Search for API URL patterns in the Enhance integration files
rg "panel\." inc/integrations/host-providers/class-enhance-host-provider.php -A 2 -B 2

# Also check for /api/ usage
rg "/api" inc/integrations/host-providers/class-enhance-host-provider.php -A 2 -B 2

# Look for API URL construction or validation
rg "api_url|base_url|endpoint" inc/integrations/host-providers/class-enhance-host-provider.php -A 3 -B 1

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 2278


🏁 Script executed:

# Check the entire Enhance host provider file for API URL handling
wc -l inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 148


🏁 Script executed:

# Get the full context of how API URLs are constructed and used
head -100 inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 2090


🏁 Script executed:

# Search for send_enhance_api_request calls to see what endpoints are used
rg "send_enhance_api_request" inc/integrations/host-providers/class-enhance-host-provider.php -A 1

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 565


🏁 Script executed:

# Look for endpoint definitions or API calls
rg "\'/api" inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 153


🏁 Script executed:

# Check around line 100-200 to see actual API endpoint usage
sed -n '100,200p' inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 3941


🏁 Script executed:

# Search for any documentation or comments about Enhance API URL format
rg "ENHANCE_API_URL" inc/integrations/host-providers/class-enhance-host-provider.php -B 3 -A 3

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 934


🏁 Script executed:

# Check if there are any tests or examples that show correct format
fd "test" inc/integrations/host-providers/ -o fd "example" inc/integrations/host-providers/

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 204


🏁 Script executed:

# Look at the complete get_fields method to see the placeholder
sed -n '97,120p' inc/integrations/host-providers/class-enhance-host-provider.php

Repository: Multisite-Ultimate/ultimate-multisite

Length of output: 784


Incorrect API URL guidance in error message at line 347.

The error message suggests users should include /api/ at the end of the API URL (e.g., https://panel.example.com/api/), but this contradicts the UI placeholder and code structure. The endpoints are constructed without /api/ prefix (e.g., /servers/{id}/domains), so the base URL should not include /api/. Update line 347 to match the placeholder example:

Change:

__('1. API URL includes /api/ at the end (e.g., https://panel.example.com/api/)', 'ultimate-multisite')

To:

__('1. API URL is correct (e.g., https://panel.example.com)', 'ultimate-multisite')
🤖 Prompt for AI Agents
In inc/integrations/host-providers/class-enhance-host-provider.php around lines
304 to 356, the troubleshooting tip incorrectly tells users to include "/api/"
at the end of the API URL; update that tip to instruct users to provide the base
panel URL without "/api/" (for example "https://panel.example.com") so it
matches the UI placeholder and how endpoints are constructed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to connect to Enhance API

2 participants