Skip to content

fix: improve JSON response handling in MCP#2

Merged
Canvinus merged 1 commit intomainfrom
json-parsing-fix
Apr 24, 2025
Merged

fix: improve JSON response handling in MCP#2
Canvinus merged 1 commit intomainfrom
json-parsing-fix

Conversation

@Canvinus
Copy link
Copy Markdown
Contributor

This pull request refactors the scripts/generate-api.js file to standardize code style, improve error handling, and enhance functionality for API client generation. The most significant changes include replacing double quotes with single quotes, improving JSON parsing for API responses, and enhancing the Zod schema generation for better type safety.

Code Style Standardization:

  • Replaced all double quotes with single quotes for consistency across the file. [1] [2] [3] [4]
  • Removed unnecessary semicolons and added consistent line breaks for cleaner formatting. [1] [2]

Error Handling Improvements:

  • Enhanced the makeApiRequest function to handle non-JSON responses gracefully by checking for special prefixes (e.g., data:, debug:) and falling back to raw text when JSON parsing fails.

Functional Enhancements:

  • Updated the Zod schema generation logic to better handle nested objects, arrays, and enums, ensuring more robust type inference. [1] [2]
  • Improved formatting for JSON.stringify in API responses to include indentation for better readability.

Output File Generation:

  • Adjusted the file-writing logic to use single quotes in file paths and updated the success message for consistency.- Add robust error handling for non-JSON API responses
  • Handle special response formats like server-sent events and HTML
  • Improve response formatting in route handlers with pretty-printing
  • Add fallback to return raw text when JSON parsing fails
  • Update generated API client and routes with improved error handling

- Add robust error handling for non-JSON API responses
- Handle special response formats like server-sent events and HTML
- Improve response formatting in route handlers with pretty-printing
- Add fallback to return raw text when JSON parsing fails
- Update generated API client and routes with improved error handling
@Canvinus Canvinus requested a review from elilambnz April 24, 2025 17:16
@Canvinus Canvinus merged commit f422a05 into main Apr 24, 2025
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.

2 participants