EnableAsync commented on code in PR #1044:
URL: https://github.com/apache/rocketmq-clients/pull/1044#discussion_r2224993652
##########
rust/src/util.rs:
##########
@@ -223,6 +223,149 @@ pub fn handle_response_status(
Ok(())
}
+/// Handle status messages in receive message responses, similar to Java
StatusChecker
+/// This function handles status codes appropriately based on the context
+pub fn handle_receive_message_status(
+ status: &Status,
+ operation: &'static str,
+) -> Result<(), ClientError> {
+ match status.code {
Review Comment:
Excellent work on this PR!
I have a suggestion to make the new handle_receive_message_status function
more concise and idiomatic by using Rust's match on the pb::Code enum with |
(OR) patterns. This would greatly reduce boilerplate and improve readability.
Here's a quick example of what it could look like:
```rust
pub fn handle_receive_message_status(...) -> Result<(), ClientError> {
let code = Code::from_i32(status.code).unwrap_or(Code::Unspecified); //
Simplified for example
match code {
// Success cases
Code::Ok | Code::MultipleResults => Ok(()),
// Config errors
Code::BadRequest
| Code::IllegalTopic
| Code::IllegalConsumerGroup
// ... other config errors
=> Err(ClientError::new(ErrorKind::Config, "bad request", ...)),
// Server errors
Code::InternalError | Code::InternalServerError => {
Err(ClientError::new(ErrorKind::Server, "internal error", ...))
}
// ... other error groups
_ => Err(ClientError::new(ErrorKind::Server, "unhandled status",
...)),
}
}
```
--
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]