Skip to content

Fix content submission error handling and JSON parsing issues - #116

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/content-submission-issues
Oct 8, 2025
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/content-submission-issues

Conversation

@ishaileshpant

Copy link
Copy Markdown
Collaborator

🔧 Fix Content Submission Error Handling

Problem

Content submission was failing with "A server e... is not valid JSON" errors, indicating that the bot API was returning non-JSON responses (likely HTML error pages) when errors occurred.

Root Causes

  1. Bot API error handling - Server errors were returning HTML instead of JSON
  2. Frontend JSON parsing - No fallback handling for non-JSON error responses
  3. Missing catch-all error handler - Some errors could bypass JSON response handling

Solution

  • Enhanced error handling in frontend to handle non-JSON responses
  • Added fallback parsing for error responses with raw text logging
  • Added final catch-all error handler in bot API to ensure valid JSON responses
  • Improved error messages for better debugging

Technical Changes

// Before - could fail on non-JSON responses
const errorData = await response.json();

// After - handles both JSON and non-JSON responses
let errorData;
try {
    errorData = await response.json();
} catch (jsonError) {
    const textResponse = await response.text();
    throw new Error(`Server error: ${response.status} - ${textResponse.substring(0, 100)}`);
}

Files Changed

  • github-auth.js - Enhanced error handling in createPullRequest method
  • api/github/create-content-pr.js - Added final catch-all error handler

Impact

  • 🎯 Resolves "A server e... is not valid JSON" errors
  • 🚀 Improves error handling and user experience
  • 🔍 Enhances debugging with better error messages
  • 🛡️ Prevents HTML error pages from breaking JSON parsing

Testing

  • Error handling now works with both JSON and non-JSON responses
  • Bot API always returns valid JSON responses
  • Better error messages for debugging
  • No linting errors

- Improve error handling in github-auth.js to handle non-JSON error responses
- Add better logging for bot API errors with raw response text
- Add final catch-all error handler in bot API to ensure valid JSON responses
- Resolves 'A server e... is not valid JSON' error in content submission
- Prevents HTML error pages from being returned as JSON responses

Changes:
1. Enhanced error handling in createPullRequest method
2. Added try-catch for JSON parsing with fallback to text response
3. Added final error handler in bot API to prevent HTML responses
4. Improved error messages for better debugging
@vercel

vercel Bot commented Oct 8, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
prepguides-dev Ready Ready Preview Comment Oct 8, 2025 6:41pm

@ishaileshpant

Copy link
Copy Markdown
Collaborator Author

/approve

@github-actions
github-actions Bot merged commit faab75c into main Oct 8, 2025
11 checks passed
@github-actions

github-actions Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

🚀 Admin-Approved and Auto-Merged!

This PR has been automatically merged to main after admin approval by @ishaileshpant.

✅ **Status**: Merged and deployed
🔗 **Commit**: `faab75c5d8a12cd31884b6de54589234265e09cf`
📅 **Merged at**: 2025-10-08T18:42:07.294Z
👤 **Approved by**: Admin/Maintainer/Owner

Thank you for your contribution! 🎉

@ishaileshpant
ishaileshpant deleted the fix/content-submission-issues branch October 13, 2025 18:19
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