When logging errors, also log payload#131
Merged
Merged
Conversation
This helps diagnose the actual issue, since it usually stems from the payload we're trying to send, and just the response error wouldn't be enough to diagnose and fix.
Member
Author
🧪 Details on Ubuntu 24.04.2 LTSfrom dotnet-retest v0.7.1 on .NET 8.0.17 with 💜 by @devlooped |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances error logging by including the outgoing payload alongside the HTTP response error, making debugging of failed WhatsApp API calls easier.
- Introduced
jsonOptionsto standardize JSON serialization settings. - Changed error handling to serialize both
payloadand parsed response into a single JSON block. - Updated the logger and exception to include the serialized payload context.
Comments suppressed due to low confidence (2)
src/WhatsApp/WhatsAppClient.cs:68
- [nitpick] The variable name
erroris ambiguous and matches the serialized property name. Consider renaming it toerrorDetailsJsonand using a more specific property name likeresponseErrorfor clarity.
var error = JsonSerializer.Serialize(new
src/WhatsApp/WhatsAppClient.cs:70
- Logging the raw
payloadmay expose sensitive data. Ensure that any personal or confidential fields are redacted or filtered before logging in production.
payload,
| var error = JsonSerializer.Serialize(new | ||
| { | ||
| payload, | ||
| error = JsonNode.Parse(await result.Content.ReadAsStringAsync()) |
There was a problem hiding this comment.
Parsing the HTTP response content without handling parse errors could throw an exception if the content isn’t valid JSON and mask the original failure. Consider wrapping the parse call in a try/catch and falling back to the raw string on parse errors.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This helps diagnose the actual issue, since it usually stems from the payload we're trying to send, and just the response error wouldn't be enough to diagnose and fix.