All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.anonymousmister.bootfastconfig.config.GlobalExceptionHandler Maven / Gradle / Ivy

package com.github.anonymousmister.bootfastconfig.config;


import com.github.anonymousmister.abnormal.ServiceRuntimeException;
import com.github.anonymousmister.bootfastconfig.L18nResultCode;
import com.github.anonymousmister.result.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @author mister
 */
@Order(100)
@RestControllerAdvice
public class GlobalExceptionHandler {
    private final static Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(ServiceRuntimeException.class)
    @ResponseBody
    public Result handleWJException(ServiceRuntimeException e) {
        LOGGER.error("捕捉到异常*****", e);
        return Result.ofFail(new L18nResultCode(e.getResultCode()), e);
    }


    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e) {
        LOGGER.error("捕捉到异常*****", e);
        return Result.ofThrowable(e);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy