Enhance error handling with categorization and helpful suggestions #2

Merged
brad merged 1 commit from :feat/better-errors into main 2026-02-06 23:52:40 -08:00
Contributor

Overview

This PR significantly improves error handling in the Midjourney MCP server by adding error categorization, helpful suggestions, and better user guidance.

Changes

New Features

  1. Error Categorization

    • New ErrorCategory enum with types:
      • content_filter - Content policy violations
      • api_error - API-specific errors
      • network_error - Connection/network issues
      • timeout - Request timeouts
      • validation_error - Invalid parameters
      • unknown - Uncategorized errors
  2. Enhanced MidAPIError Class

    • Category field for programmatic error handling
    • retryable boolean indicating if retry may succeed
    • suggestions list with actionable guidance
    • format_user_message() method for user-friendly output
  3. Content Filter Improvements

    • Detects content filter violations automatically
    • Provides specific rephrasing suggestions:
      • Remove specific names, brands, copyrighted characters
      • Use abstract/artistic language
      • Focus on emotions and settings
      • Rephrase violent concepts metaphorically
    • Clearly indicates error is not retryable without changes
  4. Better Error Messages

    • All tools now use enhanced error formatting
    • Network errors separated from HTTP errors
    • Timeout errors with specific retry guidance
    • Rate limit errors with wait time suggestions

Files Changed

  • src/midjourney_mcp/errors.py (new) - Error handling module
  • src/midjourney_mcp/api_client.py - Enhanced exception handling
  • src/midjourney_mcp/server.py - Improved error messages in all tools

Example Error Messages

Before

API error: Content filter violation

After

Error (content_filter): Content filter violation

Suggestions:
  • Try removing specific names, brands, or copyrighted characters
  • Use more abstract or artistic language instead of explicit terms
  • Focus on emotions, settings, or artistic styles rather than controversial subjects
  • If requesting art with people, describe clothing, poses, or activities in general terms
  • Rephrase violent or intense concepts in metaphorical or symbolic ways

✗ Retrying with the same parameters will not succeed.

Testing

Tested with various error scenarios:

  • Content filter violations
  • Network timeouts
  • Invalid parameters
  • API errors

Impact

This improves the user experience by:

  • Providing clear, actionable guidance when errors occur
  • Helping users understand why their request failed
  • Suggesting concrete ways to rephrase prompts
  • Indicating whether retrying makes sense
## Overview This PR significantly improves error handling in the Midjourney MCP server by adding error categorization, helpful suggestions, and better user guidance. ## Changes ### New Features 1. **Error Categorization** - New `ErrorCategory` enum with types: - `content_filter` - Content policy violations - `api_error` - API-specific errors - `network_error` - Connection/network issues - `timeout` - Request timeouts - `validation_error` - Invalid parameters - `unknown` - Uncategorized errors 2. **Enhanced MidAPIError Class** - Category field for programmatic error handling - `retryable` boolean indicating if retry may succeed - `suggestions` list with actionable guidance - `format_user_message()` method for user-friendly output 3. **Content Filter Improvements** - Detects content filter violations automatically - Provides specific rephrasing suggestions: - Remove specific names, brands, copyrighted characters - Use abstract/artistic language - Focus on emotions and settings - Rephrase violent concepts metaphorically - Clearly indicates error is not retryable without changes 4. **Better Error Messages** - All tools now use enhanced error formatting - Network errors separated from HTTP errors - Timeout errors with specific retry guidance - Rate limit errors with wait time suggestions ### Files Changed - `src/midjourney_mcp/errors.py` (new) - Error handling module - `src/midjourney_mcp/api_client.py` - Enhanced exception handling - `src/midjourney_mcp/server.py` - Improved error messages in all tools ## Example Error Messages ### Before ``` API error: Content filter violation ``` ### After ``` Error (content_filter): Content filter violation Suggestions: • Try removing specific names, brands, or copyrighted characters • Use more abstract or artistic language instead of explicit terms • Focus on emotions, settings, or artistic styles rather than controversial subjects • If requesting art with people, describe clothing, poses, or activities in general terms • Rephrase violent or intense concepts in metaphorical or symbolic ways ✗ Retrying with the same parameters will not succeed. ``` ## Testing Tested with various error scenarios: - Content filter violations - Network timeouts - Invalid parameters - API errors ## Impact This improves the user experience by: - Providing clear, actionable guidance when errors occur - Helping users understand why their request failed - Suggesting concrete ways to rephrase prompts - Indicating whether retrying makes sense
- Add new errors.py module with ErrorCategory enum and enhanced MidAPIError class
- Categorize errors into: content_filter, api_error, network_error, timeout, validation_error
- Provide actionable suggestions for each error type
- Add content filter rephrasing suggestions when prompts violate policies
- Indicate whether errors are retryable
- Enhance error messages in all tools (imagine, upscale, vary, check_status, imagine_with_style)
- Catch httpx TimeoutException and NetworkError separately for better diagnostics
- Format user-facing error messages with categories, suggestions, and retry guidance

This improves the user experience by providing clear, actionable guidance when
errors occur, especially for common issues like content filter violations.
brad merged commit 96dad66cff into main 2026-02-06 23:52:40 -08:00
brad deleted branch feat/better-errors 2026-02-06 23:52:47 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
brad/claude-midjourney-mcp!2
No description provided.