Commit f7102990 authored by wujiang's avatar wujiang

提交默认异常配置

parent cbec0fa5
...@@ -29,9 +29,9 @@ import lombok.extern.slf4j.Slf4j; ...@@ -29,9 +29,9 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@Primary @Primary
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
@Value ("${exception.debug}") @Value("${exception.debug:false}")
private boolean debug; private boolean debug;
/** /**
* 校验异常统一拦截地方 * 校验异常统一拦截地方
...@@ -48,13 +48,18 @@ public class GlobalExceptionHandler { ...@@ -48,13 +48,18 @@ public class GlobalExceptionHandler {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
response.setTraceId(RequestContext.getTraceId()); response.setTraceId(RequestContext.getTraceId());
response.setPath(request.getServletPath()); response.setPath(request.getServletPath());
// 获取异常的堆栈跟踪信息 if (debug) {
StringWriter sw = new StringWriter(); // 获取异常的堆栈跟踪信息
PrintWriter pw = new PrintWriter(sw); StringWriter sw = new StringWriter();
e.printStackTrace(pw); PrintWriter pw = new PrintWriter(sw);
String stackTrace = sw.toString(); e.printStackTrace(pw);
response.setDevMessage(stackTrace); String stackTrace = sw.toString();
response.setMessage(stackTrace); response.setDevMessage(stackTrace);
response.setMessage(stackTrace);
} else {
response.setDevMessage(e.getMessage());
response.setMessage(e.getMessage());
}
return response; return response;
} }
......
exception.debug=true
## DB properties: ## DB properties:
spring.datasource.dynamic.primary= mysql-service spring.datasource.dynamic.primary= mysql-service
spring.datasource.mysql-service.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.mysql-service.driver-class-name=com.mysql.cj.jdbc.Driver
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment