vue版本上线
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class BusinessParamCheckingException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int code;
|
||||
private Map<String, Object> data;
|
||||
|
||||
public BusinessParamCheckingException(int code, String reason) {
|
||||
super(reason);
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
objectMap.put("message", reason);
|
||||
this.code = code;
|
||||
this.data = objectMap;
|
||||
}
|
||||
|
||||
public BusinessParamCheckingException(int code, String reason, Throwable throwable) {
|
||||
super(reason, throwable);
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
objectMap.put("message", reason);
|
||||
this.code = code;
|
||||
this.data = objectMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class BusinessRunTimeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int code;
|
||||
private Map<String, Object> data;
|
||||
|
||||
public BusinessRunTimeException(int code, String reason) {
|
||||
super(reason);
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
objectMap.put("message", reason);
|
||||
this.code = code;
|
||||
this.data = objectMap;
|
||||
}
|
||||
|
||||
public BusinessRunTimeException(int code, String reason, Throwable throwable) {
|
||||
super(reason, throwable);
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
objectMap.put("message", reason);
|
||||
this.code = code;
|
||||
this.data = objectMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Object handleException(Exception e, HttpServletRequest request) {
|
||||
JSONObject status = new JSONObject();
|
||||
|
||||
// 针对业务参数异常的处理
|
||||
if (e instanceof BusinessParamCheckingException) {
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ((BusinessParamCheckingException) e).getCode());
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_DATA, ((BusinessParamCheckingException) e).getData());
|
||||
return status;
|
||||
}
|
||||
|
||||
//针对业务运行时异常的处理
|
||||
if (e instanceof BusinessRunTimeException) {
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ((BusinessRunTimeException) e).getCode());
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_DATA, ((BusinessRunTimeException) e).getData());
|
||||
return status;
|
||||
}
|
||||
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ExceptionConstants.SERVICE_SYSTEM_ERROR_CODE);
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_DATA, ExceptionConstants.SERVICE_SYSTEM_ERROR_MSG);
|
||||
log.error("Global Exception Occured => url : {}, msg : {}", request.getRequestURL(), e.getMessage());
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* create time: 2019/4/18 17:41
|
||||
* 这里输出完整的堆栈信息,否则有些异常完全不知道哪里出错了。
|
||||
*/
|
||||
log.error("Global Exception Occured => url : {}", request.getRequestURL(), e);
|
||||
e.printStackTrace();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* 封装日志打印,收集日志
|
||||
* author: ji shenghua, qq 752718 920
|
||||
*/
|
||||
public class JshException {
|
||||
|
||||
public static void readFail(Logger logger, Exception e) {
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
|
||||
ExceptionConstants.DATA_READ_FAIL_MSG);
|
||||
}
|
||||
|
||||
public static void writeFail(Logger logger, Exception e) {
|
||||
logger.error("异常码[{}],异常提示[{}],异常[{}]",
|
||||
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
|
||||
ExceptionConstants.DATA_WRITE_FAIL_MSG);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user