-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show the body regardless of what's the Content Type #249
Show the body regardless of what's the Content Type #249
Conversation
Show the body if the response, even if we expected it to be JSON, for error reporting and debugging purposes.
Caution Review failedThe pull request is closed. WalkthroughThe changes in this pull request primarily focus on enhancing the error handling capabilities within the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
pkg/uhttp/wrapper.go (1)
189-194
: Consider defining the body size limit as a constant.The implementation correctly shows the response body for better error reporting. However, the magic number 4096 used for the body size limit should be defined as a package-level constant for better maintainability.
const ( ContentType = "Content-Type" applicationJSON = "application/json" applicationXML = "application/xml" applicationFormUrlencoded = "application/x-www-form-urlencoded" applicationVndApiJSON = "application/vnd.api+json" acceptHeader = "Accept" cacheTTLMaximum = 31536000 // 31536000 seconds = one year cacheTTLDefault = 3600 // 3600 seconds = one hour + maxErrorBodySize = 4096 // Maximum size of response body to include in error messages )
Then update the error message to use this constant:
- return fmt.Errorf("unexpected content type for JSON response: %s. body: «%s»", contentHeader, logBody(resp.Body, 4096)) + return fmt.Errorf("unexpected content type for JSON response: %s. body: «%s»", contentHeader, logBody(resp.Body, maxErrorBodySize))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
pkg/uhttp/wrapper.go
(1 hunks)
🔇 Additional comments (2)
pkg/uhttp/wrapper.go (2)
183-187
: LGTM! Good addition of default content type.
The fallback to "custom-mime/empty" when the content type header is missing improves debugging by making it explicit that the header was absent rather than empty.
189-194
: Verify potential exposure of sensitive data in error messages.
While showing response bodies in error messages improves debugging, please verify that this change won't inadvertently expose sensitive information (PII, secrets, etc.) in logs or error responses.
Let's check for potential sensitive endpoints:
Show the body of the response, even if we expected it to be JSON, for error reporting and debugging purposes.
Example output:
Summary by CodeRabbit