-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to ignore business exception in feign client with hystrix. #472
Comments
Use Hystrix fallback support? https://github.com/OpenFeign/feign/tree/master/hystrix#fallback-support |
@sumit4myself Here is described concept I currently use: https://github.com/spring-cloud/spring-cloud-netflix/issues/969#issuecomment-242131309 But this is for |
@spencergibb @tjuchniewicz I don't want to write any fallbak for business exception as i need to show it to the end user. Eg. If authentication fails i need to show the message to end user. HytrixCommand accept list of exception to be ignored is there any configuration for fiegn also. |
Feign uses network for transport. Exceptions are not propagated from service to client over network by default. For now the only way I found is to use concept like this:
|
@tjuchniewicz i have implemented it in the same way. but problem is hystrix wrap my business exception with HystrixRuntimeException how can i ignore it, I dont want to off hystrix for fiegn client. code : @Component
public class ErrorResponseDecoder implements ErrorDecoder {
private ErrorDecoder delegate = new ErrorDecoder.Default();
private ObjectMapper mapper = new ObjectMapper();
@Override
public Exception decode(String methodKey, Response response) {
HttpHeaders responseHeaders = new HttpHeaders();
for (Map.Entry<String, Collection<String>> entry : response.headers().entrySet()) {
responseHeaders.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
try {
String body = Util.toString(response.body().asReader());
Map<String, String> map = new HashMap<>();
map = mapper.readValue(body, new TypeReference<Map<String, String>>() {
});
if (StringUtils.equals("com.....common.exception.BussinessException",
map.get("exception"))) {
return new BussinessException(map.get("code"), map.get("message"));
} else if (StringUtils.equals("com......common.exception.SystemException",
map.get("exception"))) {
return new SystemException(map.get("code"), map.get("message"));
}
} catch (IOException e) {
throw new SystemException(SystemErrorCode.SYSTEM_ERROR, e);
}
return delegate.decode(methodKey, response);
} } |
Code looks good. I have similar solution but I return |
@tjuchniewicz thanks, When the updated code will be available ? |
Not sure. I'm not a Netflix/Hystrix developer. Please vote for Netflix/Hystrix#1366! |
This appears to be quite old and going through the Hystrix projects, this situation should be able to be handled by using Hystrix directly. Also, the changes referenced above have been accepted into Hystrix core. I suggest that this can now be closed. |
How to ignore business exception in feign client with Hystrix.
The text was updated successfully, but these errors were encountered: