Skip to content

Commit

Permalink
Fix #1031, return RpcResult for validation exception to avoid retry.
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Jan 17, 2018
1 parent 235342e commit bade243
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.validation.Validation;
import com.alibaba.dubbo.validation.Validator;

Expand All @@ -50,7 +51,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
} catch (RpcException e) {
throw e;
} catch (Throwable t) {
throw new RpcException(t.getMessage(), t);
return new RpcResult(t);
}
}
return invoker.invoke(invocation);
Expand Down

1 comment on commit bade243

@stefli
Copy link

@stefli stefli commented on bade243 Apr 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recently, we want to use validation on the provider side(No issue on the consumer side). But we couldn't get the validation errors on the consumer side when configure the validation="true" to the service on the provider side. It can't parse the exception message by Exceptionhandler, we need ConstraintViolationExeception but it returned the wrapped RemotingException.
Now, we fixed by adding two more files to wrap the message and propertyPath from the hibernate validator, and return to client. The code snippet like::

return new RpcResult(new RpcException(new CustomViolationException(set)));

Then the exception handler can handle this RpcException, and retrieve the message & propertyPath from CustomViolationException.

Please sign in to comment.