Alanxtl commented on code in PR #3183:
URL: https://github.com/apache/dubbo-go/pull/3183#discussion_r2739554167
##########
protocol/dubbo/hessian2/hessian_response.go:
##########
Review Comment:
use switch instead
##########
protocol/dubbo/hessian2/hessian_dubbo.go:
##########
@@ -240,9 +240,22 @@ func (h *HessianCodec) ReadBody(rspObj any) error {
}
rsp, ok := rspObj.(*DubboResponse)
if !ok {
- return perrors.Errorf("java exception:%s",
exception.(string))
+ return perrors.Errorf("java exception:%v", exception)
Review Comment:
```suggestion
return perrors.Errorf("java exception: %v", exception)
```
##########
protocol/dubbo/impl/hessian_test.go:
##########
@@ -485,6 +486,45 @@ func TestMarshalResponse(t *testing.T) {
assert.NotNil(t, data)
})
+ t.Run("response with generic exception", func(t *testing.T) {
+ encoder := hessian.NewEncoder()
+ pkg := DubboPackage{
+ Header: DubboHeader{
+ Type: PackageResponse,
+ ResponseStatus: Response_OK,
+ },
+ Body: &ResponsePayload{
+ Exception: hessian2.GenericException{
+ ExceptionClass:
"com.example.UserNotFoundException",
+ ExceptionMessage: "用户不存在",
Review Comment:
全使用英文
##########
protocol/dubbo/hessian2/hessian_dubbo.go:
##########
@@ -240,9 +240,22 @@ func (h *HessianCodec) ReadBody(rspObj any) error {
}
rsp, ok := rspObj.(*DubboResponse)
if !ok {
- return perrors.Errorf("java exception:%s",
exception.(string))
+ return perrors.Errorf("java exception:%v", exception)
+ }
+ if g, ok := ToGenericException(exception); ok {
+ rsp.Exception = g
+ } else if e, ok := exception.(error); ok {
+ rsp.Exception = e
+ } else {
+ rsp.Exception = perrors.Errorf("java exception:%v",
exception)
+ }
+ if g, ok := ToGenericException(exception); ok {
+ rsp.Exception = g
+ } else if e, ok := exception.(error); ok {
+ rsp.Exception = e
+ } else {
+ rsp.Exception = perrors.Errorf("java exception:%v",
exception)
}
Review Comment:
为什么这段代码重复了两次
##########
protocol/dubbo/impl/hessian.go:
##########
@@ -85,7 +86,11 @@ func marshalResponse(encoder *hessian.Encoder, p
DubboPackage) ([]byte, error) {
if response.Exception != nil { // throw error
_ = encoder.Encode(resWithException)
- if t, ok :=
response.Exception.(java_exception.Throwabler); ok {
+ if g, ok :=
response.Exception.(*hessian2.GenericException); ok {
+ _ =
encoder.Encode(java_exception.NewDubboGenericException(g.ExceptionClass,
g.ExceptionMessage))
+ } else if g, ok :=
response.Exception.(hessian2.GenericException); ok {
+ _ =
encoder.Encode(java_exception.NewDubboGenericException(g.ExceptionClass,
g.ExceptionMessage))
+ } else if t, ok :=
response.Exception.(java_exception.Throwabler); ok {
_ = encoder.Encode(t)
} else {
_ =
encoder.Encode(java_exception.NewThrowable(response.Exception.Error()))
Review Comment:
ditto
--
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]