fix: sanitize HTML error responses and remove duplicate done event#283
Open
octo-patch wants to merge 1 commit into11cafe:mainfrom
Open
fix: sanitize HTML error responses and remove duplicate done event#283octo-patch wants to merge 1 commit into11cafe:mainfrom
octo-patch wants to merge 1 commit into11cafe:mainfrom
Conversation
When the Jaaz API is blocked by Cloudflare or other intermediaries, the OpenAI SDK raises a PermissionDeniedError whose string contains the full HTML page. This gets forwarded to the frontend, showing users raw HTML markup instead of a helpful error message. - In _handle_error: detect HTML responses (starting with '<') and replace with a clear, actionable message; truncate strings over 1000 chars - In StreamProcessor.process_stream: remove the redundant 'done' event since chat_service.py already sends it in the finally block Fixes 11cafe#258
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.
Fixes #258
Problem
When the Jaaz API is blocked by Cloudflare or other intermediaries (firewalls, rate limiters), the OpenAI SDK raises a
PermissionDeniedErrorwhose string representation contains the full HTML error page. This page is then forwarded verbatim to the frontend as the error message, showing users a wall of raw HTML markup instead of a helpful, actionable message.Example of what users see in the error toast:
Solution
1. Sanitize HTML error responses in
_handle_errorDetect when the error string starts with
<(HTML content) and replace it with a clear, user-friendly message that explains what likely happened and what to do. Also truncate any excessively long error strings (> 1000 chars) to prevent the UI from being flooded.2. Remove duplicate
doneevent fromStreamProcessor.process_streamchat_service.pyalready sends adoneevent in itsfinallyblock, which runs regardless of success, error, or cancellation.StreamProcessorwas also sending its owndoneat the end of a successful stream, causing the frontend to receive the event twice on success. Removing the redundant one fromStreamProcessorkeeps the control flow clean.Testing