com.nepxion.discovery.common.handler.RestErrorHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-common Show documentation
Show all versions of discovery-common Show documentation
Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent
package com.nepxion.discovery.common.handler;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import com.nepxion.discovery.common.constant.DiscoveryConstant;
public class RestErrorHandler extends DefaultResponseErrorHandler {
private String cause;
@Override
public void handleError(ClientHttpResponse response) throws IOException {
// 这里绝对不能关闭InputStream
InputStream inputStream = response.getBody();
cause = IOUtils.toString(inputStream, DiscoveryConstant.ENCODING_UTF_8);
}
public String getCause() {
return cause;
}
}