package com.caimei.www.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import reactor.core.publisher.Mono;

/**
 * 统一异常处理
 *
 * @author : Charles
 * @date : 2020/8/7
 */
@ControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(Exception.class)
    public String convertExceptionMsg(Exception e) {
        //自定义逻辑，可返回其他值
        e.printStackTrace();
        return "error/404";
    }

    @ExceptionHandler(IllegalAccessException.class)
    @ResponseBody
    public Mono<String> convertIllegalAccessError(Exception e) {
        //自定义逻辑，可返回其他值
        return Mono.just("illegal access");
    }
}
