
com.taotao.cloud.openfeign.feign.FeignErrorDecoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of taotao-cloud-starter-openfeign Show documentation
Show all versions of taotao-cloud-starter-openfeign Show documentation
taotao-cloud-starter-openfeign
/*
* Copyright (c) 2020-2030, Shuigedeng ([email protected] & https://blog.taotaocloud.top/).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.taotao.cloud.openfeign.feign;
import com.taotao.cloud.common.exception.FeignErrorException;
import com.taotao.cloud.common.utils.common.JsonUtils;
import com.taotao.cloud.common.utils.log.LogUtils;
import feign.Response;
import feign.Util;
import java.nio.charset.StandardCharsets;
public class FeignErrorDecoder implements feign.codec.ErrorDecoder {
@Override
public Exception decode(String methodKey, Response response) {
String errorContent = "内部服务调用错误";
try {
String res = Util.toString(response.body().asReader(StandardCharsets.UTF_8));
LogUtils.error("feign调用异常{}", res);
FeignExceptionResult feignExceptionResult = JsonUtils.toObject(res, FeignExceptionResult.class);
assert feignExceptionResult != null;
errorContent = feignExceptionResult.getMsg();
} catch (Exception e) {
LogUtils.error(e);
}
return new FeignErrorException(500, errorContent);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy