Catching Exceptions & Errors

381 views
Skip to first unread message

Ste Goddard

unread,
Jun 20, 2016, 11:03:20 AM6/20/16
to HystrixOSS
Hi

Where is the best place to capture and log errors and exceptions, below is what I current have ?

Do I need to capture and re-throw anything from the fallBack() method, or will the HystrixRuntimeException be sufficient ? 

Are there any documents which explain what causes these exceptions (like COMMAND_EXCEPTION) to be thrown ?

My run Method

        HystrixCommand hystrixCommand = new HystrixCommand(HystrixCommand.Setter
                .withGroupKey(HystrixCommandGroupKey.Factory.asKey(commandGroupName))
                .andCommandKey(HystrixCommandKey.Factory.asKey(commandKeyName))) {
            @Override
            protected Collection<RouteInfo> run() {
                Collection<RouteInfo> routes;
                try {
                    routes = searchVehicles(request, endPointConfigurationMap, rateCodeConfiguration);
                    calculateAndSetValidUntil(routes, request);
                    return routes;
                } catch (ErrorPricingEndPointBeanException | EndPointException | DateFormatException | ConfigurationException | XmlParseException e) {
                    throw new HystrixBadRequestException(e.getMessage(), e);
                }
            }


The part of the method that fires execute()

            try {
                HystrixCommand hystrixCommand = supplierSearchViaHystrix(hystrixConfiguration, request, endPointConfigurationMap, rateCodeConfiguration);
                return (Collection<RouteInfo>) hystrixCommand.execute();
            } catch (HystrixBadRequestException e) {
                if (e.getCause() instanceof ErrorPricingEndPointBeanException) {
                    throw new ErrorPricingEndPointBeanException(((ErrorPricingEndPointBeanException) e.getCause()).getErrorType(), e.getMessage());
                } else if (e.getCause() instanceof EndPointException) {
                    throw new EndPointException(e.getCause().getMessage(), e.getCause());
                } else if (e.getCause() instanceof DateFormatException) {
                    throw new DateFormatException(e.getCause().getMessage(), e.getCause());
                } else if (e.getCause() instanceof ConfigurationException) {
                    throw new ConfigurationException(e.getCause().getMessage(), e.getCause());
                } else if (e.getCause() instanceof XmlParseException) {
                    throw new XmlParseException(e.getCause().getMessage(), e.getCause());
                }
            } catch (HystrixRuntimeException e) {
                LOG.debug("--------------- HYSTRIX RTEX {} {}"+ e.getFailureType().name(), e.getFallbackException().getCause());
                throw new EndPointInterruptedException(EndPointBeanInterruptionError.valueOf(e.getFailureType().name()));
            }

The fallBack()

            @Override
            public Collection<RouteInfo> getFallback() {
                return Collections.EMPTY_LIST;
            }


Many thanks.

Matt Jacobs

unread,
Jun 20, 2016, 11:39:08 PM6/20/16
to HystrixOSS
I think the most relevant documentation is here: https://github.com/Netflix/Hystrix/wiki/How-To-Use#error-propagation.  This section also describes the individual outcomes: https://github.com/Netflix/Hystrix/wiki/Metrics-and-Monitoring#command-execution-event-types-comnetflixhystrixhystrixeventtype.  If those docs don't clear up the situation for you, that'd be helpful feedback and I can try to improve them.


Given your code above, any of the 5 named exceptions you specifically catch would result in the .execute() throwing HystrixBadRequestException to the caller.  Any other Exceptions would get caught by Hystrix internals and the fallback would be returned.  So I don't believe the "HYSTRIX RTEX" logline would ever get executed, since the only 3 cases are success, fallback, and HystrixBadRequestException.  

Hope that helps.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages