saravanakumar1987 commented on code in PR #31080:
URL: https://github.com/apache/camel/pull/31080#discussion_r4728380076
##########
components/camel-alibaba/camel-alibaba-sms/src/main/java/org/apache/camel/component/alibaba/sms/SMSProducer.java:
##########
@@ -69,12 +75,36 @@ private void sendSms(Exchange exchange,
ClientConfigurations configuration, Clie
}
SendSmsResponse response = smsClient.sendSms(request);
+ // only the Code OK means success, and tea-openapi does not check the
Code
+ if (response.getBody() == null ||
!"OK".equals(response.getBody().getCode())) {
+ throw sendSmsError(response);
+ }
exchange.getMessage().setBody(SMSUtils.toSendSmsMap(response));
if (response.getBody() != null &&
ObjectHelper.isNotEmpty(response.getBody().getRequestId())) {
exchange.getMessage().setHeader(SMSHeaders.REQUEST_ID,
response.getBody().getRequestId());
}
}
+ /**
+ * Builds a TeaException in the form that tea-openapi throws for an HTTP
status from 400 to 599. So one onException
+ * handles a Code other than OK and such a status alike.
+ */
+ private static TeaException sendSmsError(SendSmsResponse response) {
+ SendSmsResponseBody body = response.getBody();
+ Map<String, Object> data = body != null ? new HashMap<>(body.toMap())
: new HashMap<>();
+ // as in the JSON of a response, a field that the service did not send
has no key
+ data.values().removeIf(Objects::isNull);
+ if (response.getStatusCode() != null) {
+ data.put("statusCode", response.getStatusCode());
+ }
+ return new TeaException(
+ Map.of(
+ "code", String.valueOf(data.get("Code")),
+ "message", "code: " + response.getStatusCode() + ", "
+ data.get("Message") + " request id: "
+ + data.get("RequestId"),
Review Comment:
Fixed in 1258938a89: the message now holds `(no message)` and `(none)` for a
missing `Message` or `RequestId`, as suggested. The same two tests now check
the whole message.
_Claude Code on behalf of saravanakumar1987_
--
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]