Commit 8a27fb64 authored by 赵啸非's avatar 赵啸非

提交配置校验

parent 1b00f31a
...@@ -25,8 +25,6 @@ import javax.servlet.http.HttpServletResponse; ...@@ -25,8 +25,6 @@ import javax.servlet.http.HttpServletResponse;
@Slf4j @Slf4j
public class ExceptionHandle { public class ExceptionHandle {
@Autowired
private HttpServletRequest request;
@Autowired @Autowired
private HttpServletResponse response; private HttpServletResponse response;
......
...@@ -7,6 +7,7 @@ import com.mortals.framework.exception.AppException; ...@@ -7,6 +7,7 @@ import com.mortals.framework.exception.AppException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -21,8 +22,6 @@ import javax.servlet.http.HttpServletResponse; ...@@ -21,8 +22,6 @@ import javax.servlet.http.HttpServletResponse;
@Slf4j @Slf4j
public class ExceptionHandle { public class ExceptionHandle {
@Autowired
private HttpServletRequest request;
@Autowired @Autowired
private HttpServletResponse response; private HttpServletResponse response;
...@@ -43,14 +42,13 @@ public class ExceptionHandle { ...@@ -43,14 +42,13 @@ public class ExceptionHandle {
stack.getClassName(), stack.getMethodName(), stack.getLineNumber(), e.getClass().getName()); stack.getClassName(), stack.getMethodName(), stack.getLineNumber(), e.getClass().getName());
AppException ex = (AppException) e; AppException ex = (AppException) e;
ret.put(KEY_RESULT_MSG, ex.getMessage()); ret.put(KEY_RESULT_MSG, ex.getMessage());
} } else if (e instanceof HttpMessageNotReadableException || e instanceof MethodArgumentTypeMismatchException) {
if (e instanceof HttpMessageNotReadableException) {
log.error("[system error]", e); log.error("[system error]", e);
response.setStatus(HttpStatus.HTTP_BAD_REQUEST); response.setStatus(HttpStatus.HTTP_BAD_REQUEST);
ret.put(KEY_RESULT_MSG, "参数错误,"+ StrUtil.subBefore(e.getMessage(), ";", false)); ret.put(KEY_RESULT_MSG, "参数错误," + StrUtil.subBefore(e.getMessage(), ";", false));
} else { } else {
log.error("[system error]", e); log.error("[system error]", e);
response.setStatus(HttpStatus.HTTP_INTERNAL_ERROR); response.setStatus(HttpStatus.HTTP_BAD_REQUEST);
ret.put(KEY_RESULT_MSG, "未知错误!" + e.getMessage()); ret.put(KEY_RESULT_MSG, "未知错误!" + e.getMessage());
} }
return ret.toJSONString(); return ret.toJSONString();
......
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