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());
        }
    }
}
