fix: log response body and status code on unmarshal failure#181
Open
15666668904 wants to merge 2 commits intolarksuite:v2_mainfrom
Open
fix: log response body and status code on unmarshal failure#18115666668904 wants to merge 2 commits intolarksuite:v2_mainfrom
15666668904 wants to merge 2 commits intolarksuite:v2_mainfrom
Conversation
When UnmarshalRespUtil.unmarshalResp() fails to deserialize the HTTP response, the original status code and response body are silently lost, making it impossible to diagnose the root cause (e.g. network gateway returning HTML instead of JSON). Changes: - Log a warning when HTTP status code is not 2xx - Log an error with status code and truncated body (max 500 chars) when JSON deserialization fails - Add unit tests covering success, invalid JSON, non-2xx with valid JSON, HTML response, and body truncation scenarios The response body is truncated to 500 characters to avoid leaking sensitive data and to prevent log flooding. Closes larksuite#163 Relates to larksuite#142, larksuite#133
The surefire plugin had <skipTests>true</skipTests> hardcoded in its
configuration block, which cannot be overridden by -DskipTests=false
from the command line.
Changed to use a Maven property reference <skipTests>${skipTests}</skipTests>
with a default value of true in <properties>, so that:
- Default behavior is unchanged (tests are skipped)
- Developers can run tests with: mvn test -DskipTests=false
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
When
UnmarshalRespUtil.unmarshalResp()fails to deserialize the HTTP response, the original status code and response body are silently lost, making it impossible to diagnose the root cause.For example, when a network gateway returns HTML instead of JSON, the caller only sees:
with no indication of what the server actually returned or what the HTTP status code was.
Changes
Gson.fromJson()throws an exception, log the HTTP status code and response body at ERROR level before re-throwing.TestUnmarshalRespUtilwith 6 test cases covering success path, invalid JSON, string-instead-of-object, HTML response, non-2xx with valid JSON, and long body truncation.Related Issues
Closes #163
Relates to #142, #133
Test Plan
mvn surefire:test -pl larksuite-oapi -Dtest=TestUnmarshalRespUtil)