-
-
Notifications
You must be signed in to change notification settings - Fork 67
Improve Enhance API integration error handling and debugging #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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>
WalkthroughThe 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Areas requiring attention:
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
🔨 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! Login credentials: |
There was a problem hiding this 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_levelparameter ofwu_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
📒 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_IDinwp-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.
| 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 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 1Repository: 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.phpRepository: 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.phpRepository: 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 1Repository: 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.phpRepository: 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.phpRepository: 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 3Repository: 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.phpRepository: 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.
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:Improved
on_add_domain()method:Better
on_remove_domain()method:Benefits
Example Error Message
Before:
After:
Testing
Closes
Closes #290
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.