package com.leanwo.activiti.service.base.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Response;
import feign.codec.ErrorDecoder;

/**
 * 不进入熔断，直接抛出异常
 * @author YangZhiJie
 * @date 2020/08/03
 */
@Configuration
public class KeepErrMsgConfiguration {
    
    @Bean
    public ErrorDecoder errorDecoder() {
        return new UserErrorDecoder();
    }

    /**
     * 自定义错误
     */
    public class UserErrorDecoder implements ErrorDecoder {
        private Logger logger = LoggerFactory.getLogger(getClass());

        @Override
        public Exception decode(String methodKey, Response response) {
            String errorMessage = response.body().toString();
            return new Exception(errorMessage);
        }
    }
}
