Copilot commented on code in PR #9567:
URL: https://github.com/apache/seatunnel/pull/9567#discussion_r2227078618
##########
seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java:
##########
@@ -128,15 +131,16 @@ public HttpResponse execute(
Map<String, Object> bodyMap = new HashMap<>();
// If body is set but bodyMap is not, convert body to bodyMap
if (!Strings.isNullOrEmpty(body)) {
- bodyMap =
- ConfigFactory.parseString(body).entrySet().stream()
- .collect(
- Collectors.toMap(
- Map.Entry::getKey,
- entry ->
entry.getValue().unwrapped(),
- (v1, v2) -> v2));
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ TypeReference<Map<String, Object>> typeReference =
+ new TypeReference<Map<String, Object>>() {};
+ bodyMap = objectMapper.readValue(body, typeReference);
+ } catch (Exception e) {
Review Comment:
Catching generic Exception is too broad. Consider catching specific
exceptions like JsonProcessingException or IOException to handle JSON parsing
errors more precisely and allow unexpected exceptions to propagate
appropriately.
##########
seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java:
##########
@@ -128,15 +131,16 @@ public HttpResponse execute(
Map<String, Object> bodyMap = new HashMap<>();
// If body is set but bodyMap is not, convert body to bodyMap
if (!Strings.isNullOrEmpty(body)) {
- bodyMap =
- ConfigFactory.parseString(body).entrySet().stream()
- .collect(
- Collectors.toMap(
- Map.Entry::getKey,
- entry ->
entry.getValue().unwrapped(),
- (v1, v2) -> v2));
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ TypeReference<Map<String, Object>> typeReference =
+ new TypeReference<Map<String, Object>>() {};
+ bodyMap = objectMapper.readValue(body, typeReference);
+ } catch (Exception e) {
+ log.error("body formatting exception, body:[{}]", body);
+ throw new SeaTunnelException(e.getMessage());
Review Comment:
The error message only includes the original exception message without
context about the body formatting failure. Consider providing a more
descriptive message like 'Failed to parse HTTP request body: ' + e.getMessage()
to help users understand the issue.
```suggestion
throw new SeaTunnelException("Failed to parse HTTP request
body: " + e.getMessage());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]