{{ message }}
refactor: extract duplicated code into shared utility classes#2
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: extract duplicated code into shared utility classes#2devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- JsonUtils: escapeJsonString() and throwableToString() - ResponseBuilder: WebSocket/HTTP error JSON construction and send-error-and-close pattern - HttpProxyUtils: HTTP proxy logic and image proxy helper (proxyImageRequest) Also fixes a bug where NewBingGoGoClientWebSocket.onError() did not escape the error message JSON string. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
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
Extracted repeated patterns across
NewBingGoGoServerandNewBingGoGoClientWebSocketinto three shared utility classes undercn.jja8.newbinggogo.util:JsonUtils— general-purpose string helpers:escapeJsonString(String)— JSON string escaping (moved fromNewBingGoGoServer)throwableToString(Throwable)— stack trace to string (moved fromNewBingGoGoServer.printErrorToString)ResponseBuilder— all error response construction:buildWebSocketErrorJson(message)— the{"type":2,"result":{"value":"Error",...}}format used by bothgetReturnErrorWebSocketandNewBingGoGoClientWebSocket.onErrorsendWebSocketErrorAndClose(ws, message)— the send-error-then-close pattern duplicated across both classeshttpError(...)overloads — the HTTP JSON error response (replacesgetReturnError)HttpProxyUtils— HTTP proxy forwarding:proxyGet(session, url [, headers])— the full proxy logic (URL open → copy headers → read response) previously inline inNewBingGoGoServer.goUrlproxyImageRequest(session, url, referer)— eliminates the duplicated create-headers/set-mime-type pattern used by both/images/createand/images/create/async/resultshandlersAlso fixes a latent bug:
NewBingGoGoClientWebSocket.onError()previously built error JSON without callingescapeJsonString, which could produce malformed JSON if the exception message contained quotes or backslashes. Now routes throughResponseBuilder.buildWebSocketErrorJsonwhich always escapes.NewBingGoGoServershrinks from 252 → 108 lines; all routing logic is now ~30 lines of clean delegation.Link to Devin session: https://app.devin.ai/sessions/476cc2aa4b54433e9bd06a53961958e9
Requested by: @oneky