记得上下班打卡 | git大法好,push需谨慎

Commit 075773f6 authored by 张国柄's avatar 张国柄

~ex.handler;

parent 0b7228e0
......@@ -9,6 +9,7 @@ import com.liquidnet.common.exception.constant.ErrorCode;
import com.liquidnet.common.exception.entity.Error;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
......@@ -36,25 +37,30 @@ import javax.validation.ConstraintViolationException;
@ControllerAdvice(annotations = RestController.class)
public class RestControllerAdviceHandler {
private final Logger logger = LoggerFactory.getLogger(RestControllerAdviceHandler.class);
@Value("${spring.profiles.active:prod}")
private String active;
@ExceptionHandler(value = Exception.class)
@ResponseBody
public ResponseEntity<Error> serviceExceptionHandler(Exception rex, HttpServletRequest req) {
logger.error("Ex.Handler.RestController:uri:{},param:{},ex:{},msg:{},",
req.getRequestURI(), JSON.toJSONString(req.getParameterMap()), rex.getClass().getSimpleName(), rex.getLocalizedMessage());
logger.warn("Ex.Rest[uri:{},param:{},ex:{},msg:{}]", req.getRequestURI(), JSON.toJSONString(req.getParameterMap()),
rex.getClass().getSimpleName(), rex.getMessage());
if (rex instanceof HttpMessageNotReadableException) {
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(ErrorCode.HTTP_PARAM_ERROR.getMessage()), HttpStatus.OK);
}
if (rex instanceof MissingServletRequestParameterException) {
String message = ErrorCode.HTTP_PARAM_ERROR.getMessage();
if (!"prod".equals(active)) {
MissingServletRequestParameterException ygex = (MissingServletRequestParameterException) rex;
String message = ygex.getMessage();
message = ygex.getMessage();
}
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(message), HttpStatus.OK);
}
if (rex instanceof ConstraintViolationException) {
ConstraintViolationException ygex = (ConstraintViolationException) rex;
ConstraintViolation violation = (ConstraintViolation) ygex.getConstraintViolations().toArray()[0];
String violationNode = violation.getPropertyPath().toString();
// String violationNode = violation.getPropertyPath().toString();
// String message = violationNode.substring(violationNode.indexOf(".") + 1) + violation.getMessage();
String message = violation.getMessage();
return new ResponseEntity<>(Error.getNew().setCode(ErrorCode.HTTP_PARAM_ERROR.getCode()).setMessage(message), HttpStatus.OK);
......
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