Copilot commented on code in PR #713:
URL: https://github.com/apache/dubbo-go-pixiu/pull/713#discussion_r2247185301


##########
pkg/filter/accesslog/access_log.go:
##########
@@ -138,7 +141,12 @@ func buildAccessLogMsg(c *http.HttpContext, cost 
time.Duration) string {
                builder.WriteString(fmt.Sprintf("invoke err [ %v", err))
                builder.WriteString("] ")
        }
-       resp := c.TargetResp.(*client.UnaryResponse).Data
+       var resp []byte
+       if unaryResponse, ok := c.TargetResp.(*client.UnaryResponse); ok {
+               resp = unaryResponse.Data
+       } else {
+               resp = []byte("received a non-unary response")

Review Comment:
   The hardcoded error message "received a non-unary response" should be 
defined as a constant to improve maintainability and consistency.
   ```suggestion
                resp = []byte(NonUnaryResponseErrorMsg)
   ```



##########
pkg/filter/accesslog/access_log.go:
##########
@@ -138,7 +141,12 @@ func buildAccessLogMsg(c *http.HttpContext, cost 
time.Duration) string {
                builder.WriteString(fmt.Sprintf("invoke err [ %v", err))
                builder.WriteString("] ")
        }
-       resp := c.TargetResp.(*client.UnaryResponse).Data
+       var resp []byte
+       if unaryResponse, ok := c.TargetResp.(*client.UnaryResponse); ok {
+               resp = unaryResponse.Data
+       } else {

Review Comment:
   Consider adding a comment explaining when non-unary responses might occur 
and what this fallback behavior achieves in the access log context.
   ```suggestion
        } else {
                // Fallback behavior: If the response is not a unary response, 
log a placeholder message.
                // Non-unary responses might occur in cases where the target 
service returns a streaming
                // or other non-standard response type. This ensures the access 
log captures such cases
                // explicitly, aiding in debugging and monitoring.
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to