Fix AJAX endpoints returning HTML instead of JSON on transient errors#498
Open
scott2b wants to merge 1 commit into
Open
Fix AJAX endpoints returning HTML instead of JSON on transient errors#498scott2b wants to merge 1 commit into
scott2b wants to merge 1 commit into
Conversation
Users intermittently see "Unexpected token '<', <!DOCTYPE..." when saving because transient DB failures or session issues cause the server to return HTML (Flask default error pages or login redirects) instead of JSON. Server-side: add AJAX detection, return JSON errors from auth decorators and Flask error handlers, eliminate redundant DB call in require_user_id. Client-side: detect HTML/parseerror responses and show actionable messages. Deploy: align gunicorn timeout (90s) with S3 timeout (60s) and nginx (95s). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Unexpected token '<', "<!DOCTYPE "...errors when saving StoryMaps. The error is transient — retrying works. Root cause: transient DB failures or session expiry cause the server to return HTML (Flask default 500 pages or login redirect) instead of JSON, which jQuery can't parse.@app.errorhandlerfor 401/403/500 as a safety net. Eliminated redundantget_session_user()call in@require_user_id. Added missing@require_usertostorymap_export.parseerror(HTML response), HTTP 401/502/503/504, and timeouts — shows actionable messages like "Your session has expired. Reload this page to sign back in." instead of raw JSON parse errors.--timeout 90(was default 30s, shorter than S3's 60s read timeout) and nginxproxy_read_timeout 95sto prevent worker kills during slow S3 operations.Test plan
🤖 Generated with Claude Code