Commit 92e3ca66 by 罗承锋

统一异常处理

parent 5992c732
package com.winsun.advice;
import com.winsun.auth.core.common.model.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @author chengfengluo
* @date 2022-03-15 11:08
*/
@Slf4j
@RestControllerAdvice
public class ErrorControllerAdvice {
private final static Integer errorLength = 20;
@ExceptionHandler(Exception.class)
public ResponseData<String> allErrorHandler(Exception e) {
String message = e.getMessage();
if (StringUtils.isNotBlank(message) && message.length() > errorLength) {
return ResponseData.error("系统异常!");
}else {
return ResponseData.error(e.getMessage());
}
}
}
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