mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
2.0
This commit is contained in:
@@ -114,4 +114,9 @@ public class OpenContextImpl<T> implements OpenContext<T> {
|
||||
}
|
||||
return JSON.parseObject(bizContent, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return rootJsonObject.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -76,12 +76,6 @@ public class BaseServiceConfiguration extends WebMvcConfigurationSupport
|
||||
return new GlobalExceptionHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ErrorController errorController() {
|
||||
return new ErrorController();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ServiceRouteController serviceRouteInfoHandler() {
|
||||
|
@@ -1,27 +0,0 @@
|
||||
package com.gitee.sop.servercommon.configuration;
|
||||
|
||||
import com.gitee.sop.servercommon.bean.ServiceConfig;
|
||||
import com.gitee.sop.servercommon.exception.ServiceException;
|
||||
import com.gitee.sop.servercommon.result.ServiceResultBuilder;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class ErrorController {
|
||||
|
||||
@RequestMapping("/error")
|
||||
public Object error(HttpServletRequest request, HttpServletResponse response) {
|
||||
return getResult(request, response);
|
||||
}
|
||||
|
||||
protected Object getResult(HttpServletRequest request, HttpServletResponse response) {
|
||||
ServiceResultBuilder serviceResultBuilder = ServiceConfig.getInstance().getServiceResultBuilder();
|
||||
return serviceResultBuilder.buildError(request, response, new ServiceException("系统繁忙"));
|
||||
}
|
||||
}
|
@@ -1,6 +1,8 @@
|
||||
package com.gitee.sop.servercommon.configuration;
|
||||
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ServiceConfig;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.servercommon.exception.ServiceException;
|
||||
import com.gitee.sop.servercommon.result.ServiceResultBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -14,6 +16,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@@ -40,6 +43,7 @@ public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 捕获手动抛出的异常
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param exception
|
||||
@@ -54,22 +58,24 @@ public class GlobalExceptionHandler {
|
||||
|
||||
/**
|
||||
* 捕获未知异常
|
||||
* @param request
|
||||
* @param response
|
||||
* @param exception
|
||||
* @return
|
||||
*
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @param exception 异常信息
|
||||
* @return 返回提示信息
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Object exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
response.addHeader(X_SERVICE_ERROR_CODE, String.valueOf(SYSTEM_ERROR_CODE));
|
||||
log.error("系统错误", exception);
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
log.error("系统错误, openContext:{}", openContext == null ? "null" : openContext, exception);
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(exception.getMessage());
|
||||
StackTraceElement[] stackTrace = exception.getStackTrace();
|
||||
// 取5行错误内容
|
||||
int lineCount = 5;
|
||||
for (int i = 0; i < stackTrace.length && i < lineCount ; i++) {
|
||||
for (int i = 0; i < stackTrace.length && i < lineCount; i++) {
|
||||
StackTraceElement stackTraceElement = stackTrace[i];
|
||||
msg.append("<br> at ").append(stackTraceElement.toString());
|
||||
}
|
||||
@@ -80,9 +86,9 @@ public class GlobalExceptionHandler {
|
||||
/**
|
||||
* 处理异常
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param exception
|
||||
* @param request request
|
||||
* @param response response
|
||||
* @param exception 异常信息
|
||||
* @return 返回最终结果
|
||||
*/
|
||||
protected Object processError(HttpServletRequest request, HttpServletResponse response, Exception exception) {
|
||||
|
Reference in New Issue
Block a user