Skip to content

Improved Midjourney Response Handling #16

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

harry81
Copy link

@harry81 harry81 commented Apr 27, 2025

This PR introduces an environment-aware logging system and fixes Midjourney API response handling. The changes improve debugging capabilities while maintaining clean production logs.

Key Changes

  • Fixed image URL parsing for Midjourney responses by properly handling temporary_image_urls
  • Added environment detection via command line arguments (--env=production/development)
  • Created a centralized logger with environment-specific log levels
  • Standardized all parsing functions to use the global logger when no custom logger is provided
  • Improved output size awareness to prevent console crashes with large JSON responses
  • Enhanced task progress reporting with more detailed information

Why These Changes Are Needed

The existing logging system had two main issues:

  1. Midjourney API responses were not properly handled, causing missing images when the API returned URLs in the temporary_image_urls field instead of the standard image_urls field

Problems Solved

  • Users now receive all images from Midjourney responses, regardless of which field contains the URLs
  • Development environments now receive detailed logs while production environments only receive warnings and errors
  • Console performance is improved by avoiding logging of large JSON objects
  • Debugging is easier with more consistent and detailed task progress information

The changes are ready for review.

harry81 added 3 commits April 27, 2025 22:33
- Add logger parameter to all output parsing functions for better error tracking
- Implement detailed logging for task status, progress and errors
- Add additional error handling for edge cases such as missing output
- Fix image URL parsing for Midjourney responses with temporary_image_urls
- Improve output size awareness in logs to prevent console crashes
- Add more descriptive task identification in log messages
- Add command line argument parsing for environment detection
- Create centralized logger with environment-specific log levels
- Replace direct console logging with environment-aware logger
- Improve task status logging with more detailed information
- Standardize parsing functions to use the global logger when no custom logger is provided
- Add better debug output handling for large response objects
Changed debug/info logs in development environment and warning/error logs
in all environments to use process.stderr.write instead of console API.
This ensures log output is consistently delivered to the standard error stream,
improving log collection and analysis.
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.

1 participant