Commit b1975ace by qiuweili123

add ProtocolExceptionHandler

parent 8b74f2a4
...@@ -4,6 +4,7 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode; ...@@ -4,6 +4,7 @@ import com.secoo.mall.common.core.errorcode.CommonErrorCode;
import com.secoo.mall.common.core.exception.BusinessException; import com.secoo.mall.common.core.exception.BusinessException;
import com.secoo.mall.common.core.exception.ParameterException; import com.secoo.mall.common.core.exception.ParameterException;
import com.secoo.mall.common.core.exception.SystemInternalException; import com.secoo.mall.common.core.exception.SystemInternalException;
import com.secoo.mall.common.handler.ProtocolExceptionHandler;
import com.secoo.mall.common.util.log.LoggerUtil; import com.secoo.mall.common.util.log.LoggerUtil;
import com.secoo.mall.common.util.response.ResponseUtil; import com.secoo.mall.common.util.response.ResponseUtil;
import com.secoo.mall.web.annotation.ApiController; import com.secoo.mall.web.annotation.ApiController;
...@@ -23,11 +24,13 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; ...@@ -23,11 +24,13 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import javax.annotation.Resource; import javax.annotation.Resource;
@RestControllerAdvice(annotations = ApiController.class) @RestControllerAdvice(annotations = ApiController.class)
public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> { public class ControllerResponseAdvice extends ProtocolExceptionHandler implements ResponseBodyAdvice<Object> {
/*
@Resource @Resource
private MessageSource messageSource; private MessageSource messageSource;
*/
@ExceptionHandler(BusinessException.class) /* @ExceptionHandler(BusinessException.class)
public Object businessExcepstionHandler(BusinessException e) { public Object businessExcepstionHandler(BusinessException e) {
LoggerUtil.warn("businessException info:", e); LoggerUtil.warn("businessException info:", e);
return ResponseUtil.getFailResponse(e.getCode(), getMsg(e)); return ResponseUtil.getFailResponse(e.getCode(), getMsg(e));
...@@ -44,7 +47,7 @@ public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> { ...@@ -44,7 +47,7 @@ public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
public Object exceptionHandler(Exception e) { public Object exceptionHandler(Exception e) {
LoggerUtil.error(e); LoggerUtil.error(e);
return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg()); return ResponseUtil.getFailResponse(CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getCode(), CommonErrorCode.SYSTEM_INTERNAL_EXCEPTION.getMsg());
} }*/
@Override @Override
public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) { public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
...@@ -56,7 +59,7 @@ public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> { ...@@ -56,7 +59,7 @@ public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
return ResponseUtil.getSuccessResponse(o); return ResponseUtil.getSuccessResponse(o);
} }
private String getMsg(BusinessException e) { /* private String getMsg(BusinessException e) {
return messageSource.getMessage(e.getMsg(), e.getArgs(), LocaleContextHolder.getLocale()); return messageSource.getMessage(e.getMsg(), e.getArgs(), LocaleContextHolder.getLocale());
} }*/
} }
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