代码优化

This commit is contained in:
冷冷 2018-02-23 20:45:12 +08:00
parent d071985eca
commit ed5afa1a71
2 changed files with 12 additions and 4 deletions

View File

@ -20,9 +20,11 @@ import java.io.InputStream;
@Slf4j
@Component
public class AuthFallbackProvider implements FallbackProvider {
private static final String AUTH_SERVICE_DISABLE = "授权模块不可用";
@Override
public ClientHttpResponse fallbackResponse(Throwable cause) {
log.error("调用:{} 异常:{}", getRoute(), cause.getMessage());
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() {
@ -46,9 +48,11 @@ public class AuthFallbackProvider implements FallbackProvider {
@Override
public InputStream getBody() {
if (cause != null && cause.getMessage() != null) {
log.error("调用:{} 异常:{}", getRoute(), cause.getMessage());
return new ByteArrayInputStream(cause.getMessage().getBytes());
} else {
return new ByteArrayInputStream("授权模块不可用".getBytes());
log.error("调用:{} 异常:{}", getRoute(), AUTH_SERVICE_DISABLE);
return new ByteArrayInputStream(AUTH_SERVICE_DISABLE.getBytes());
}
}

View File

@ -20,9 +20,11 @@ import java.io.InputStream;
@Slf4j
@Component
public class UpmsFallbackProvider implements FallbackProvider {
private static final String UPMS_SERVICE_DISABLE = "权限管理模块不可用";
@Override
public ClientHttpResponse fallbackResponse(Throwable cause) {
log.error("调用:{} 异常:{}", getRoute(), cause.getMessage());
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() {
@ -46,9 +48,11 @@ public class UpmsFallbackProvider implements FallbackProvider {
@Override
public InputStream getBody() {
if (cause != null && cause.getMessage() != null) {
log.error("调用:{} 异常:{}", getRoute(), cause.getMessage());
return new ByteArrayInputStream(cause.getMessage().getBytes());
} else {
return new ByteArrayInputStream("权限管理模块不可用".getBytes());
log.error("调用:{} 异常:{}", getRoute(), UPMS_SERVICE_DISABLE);
return new ByteArrayInputStream(UPMS_SERVICE_DISABLE.getBytes());
}
}