print fizz runtime exception log #262

This commit is contained in:
Francis Dong
2021-08-02 17:21:50 +08:00
committed by dxfeng10
parent 7577646770
commit 4014d0a8a6
5 changed files with 40 additions and 19 deletions

View File

@@ -84,6 +84,7 @@ public class FilterExceptionHandlerConfig {
}
if (t instanceof FizzRuntimeException) {
FizzRuntimeException ex = (FizzRuntimeException) t;
log.error(ex.getMessage(), LogService.BIZ_ID, exchange.getRequest().getId(), ex);
resp.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
RespEntity rs = null;
String reqId = exchange.getRequest().getId();

View File

@@ -19,6 +19,8 @@ package we.fizz.input;
import we.fizz.component.ComponentHelper;
import we.fizz.exception.FizzRuntimeException;
import we.fizz.input.extension.request.RequestInput;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -26,12 +28,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author linwaiwai
*
*/
public class InputFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(InputFactory.class);
public static Map<InputType, Class> inputClasses = new HashMap<InputType, Class>();
public static void registerInput(InputType type, Class inputClass){
inputClasses.put(type, inputClass);
@@ -53,8 +59,9 @@ public class InputFactory {
constructor = InputConfigClass.getDeclaredConstructor(Map.class);
constructor.setAccessible(true);
inputConfig = (InputConfig) constructor.newInstance(config);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new FizzRuntimeException(e.getMessage());
} catch (Exception e) {
LOGGER.error("failed to create input config, error: {}", e.getMessage(), e);
throw new FizzRuntimeException("failed to create input config, message: " + e.getMessage(), e);
}
inputConfig.setType(typeEnum);
inputConfig.setDataMapping((Map<String, Object>) config.get("dataMapping"));
@@ -76,8 +83,9 @@ public class InputFactory {
constructor.setAccessible(true);
input = (Input) constructor.newInstance();
return input;
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new FizzRuntimeException(e.getMessage());
} catch (Exception e) {
LOGGER.error("failed to create input config, error: {}", e.getMessage(), e);
throw new FizzRuntimeException("failed to create input config, message: " + e.getMessage(), e);
}
}
return null;

View File

@@ -18,7 +18,7 @@ package we.fizz.input.extension.dubbo;
import java.util.Map;
import org.springframework.util.StringUtils;
import org.apache.commons.lang3.StringUtils;
import we.fizz.exception.FizzRuntimeException;
import we.fizz.input.InputConfig;
@@ -43,33 +43,37 @@ public class DubboInputConfig extends InputConfig {
public void parse() {
String serviceName = (String) configMap.get("serviceName");
if (StringUtils.isEmpty(serviceName)) {
if (StringUtils.isBlank(serviceName)) {
throw new FizzRuntimeException("service name can not be blank");
}
setServiceName(serviceName);
String version = (String) configMap.get("version");
if (!StringUtils.isEmpty(version)) {
if (!StringUtils.isBlank(version)) {
setVersion(version);
}
String group = (String) configMap.get("group");
if (!StringUtils.isEmpty(group)) {
if (!StringUtils.isBlank(group)) {
setGroup(group);
}
String method = (String) configMap.get("method");
if (StringUtils.isEmpty(method)) {
if (StringUtils.isBlank(method)) {
throw new FizzRuntimeException("method can not be blank");
}
setMethod(method);
String paramTypes = (String) configMap.get("paramTypes");
if (!StringUtils.isEmpty(paramTypes)) {
if (!StringUtils.isBlank(paramTypes)) {
setParamTypes(paramTypes);
}
if (configMap.get("timeout") != null) {
setTimeout(Integer.valueOf(configMap.get("timeout").toString()));
if (configMap.get("timeout") != null && StringUtils.isNotBlank(configMap.get("timeout").toString())) {
try {
setTimeout(Integer.valueOf(configMap.get("timeout").toString()));
} catch (Exception e) {
throw new RuntimeException("invalid timeout: " + configMap.get("timeout").toString() + " " + e.getMessage(), e);
}
}
}

View File

@@ -22,7 +22,7 @@ import we.fizz.input.InputConfig;
import java.util.Map;
import org.springframework.util.StringUtils;
import org.apache.commons.lang3.StringUtils;
/**
*
@@ -42,19 +42,23 @@ public class GrpcInputConfig extends InputConfig {
public void parse() {
String serviceName = (String) configMap.get("serviceName");
if (StringUtils.isEmpty(serviceName)) {
if (StringUtils.isBlank(serviceName)) {
throw new FizzRuntimeException("service name can not be blank");
}
setServiceName(serviceName);
String method = (String) configMap.get("method");
if (StringUtils.isEmpty(method)) {
if (StringUtils.isBlank(method)) {
throw new FizzRuntimeException("method can not be blank");
}
setMethod(method);
if (configMap.get("timeout") != null) {
setTimeout(Integer.valueOf(configMap.get("timeout").toString()));
if (configMap.get("timeout") != null && StringUtils.isNotBlank(configMap.get("timeout").toString())) {
try {
setTimeout(Integer.valueOf(configMap.get("timeout").toString()));
} catch (Exception e) {
throw new RuntimeException("invalid timeout: " + configMap.get("timeout").toString() + " " + e.getMessage(), e);
}
}
}

View File

@@ -74,8 +74,12 @@ public class RequestInputConfig extends InputConfig {
} else {
setMethod("GET");
}
if (configBody.get("timeout") != null) {
timeout = Integer.valueOf(configBody.get("timeout").toString());
if (configBody.get("timeout") != null && StringUtils.isNotBlank(configBody.get("timeout").toString())) {
try {
timeout = Integer.valueOf(configBody.get("timeout").toString());
} catch (Exception e) {
throw new RuntimeException("invalid timeout: " + configBody.get("timeout").toString() + " " + e.getMessage(), e);
}
}
if (configBody.get("fallback") != null) {
Map<String,String> fallback = (Map<String,String>)configBody.get("fallback");