Search in sources :

Example 1 with ResponseStatus

use of com.zyd.blog.business.enums.ResponseStatus in project OneBlog by zhangyd-c.

the class ExceptionHandleController method handle.

@ExceptionHandler(value = Exception.class)
@ResponseBody
public ResponseVO handle(Throwable e) {
    if (e instanceof ZhydException || e instanceof GlobalFileException) {
        return ResultUtil.error(e.getMessage());
    }
    if (e instanceof UndeclaredThrowableException) {
        e = ((UndeclaredThrowableException) e).getUndeclaredThrowable();
    }
    ResponseStatus responseStatus = ResponseStatus.getResponseStatus(e.getMessage());
    if (responseStatus != null) {
        log.error(responseStatus.getMessage());
        return ResultUtil.error(responseStatus.getCode(), responseStatus.getMessage());
    }
    // 打印异常栈
    e.printStackTrace();
    return ResultUtil.error(CommonConst.DEFAULT_ERROR_CODE, ResponseStatus.ERROR.getMessage());
}
Also used : ZhydException(com.zyd.blog.framework.exception.ZhydException) ResponseStatus(com.zyd.blog.business.enums.ResponseStatus) GlobalFileException(com.zyd.blog.file.exception.GlobalFileException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseStatus (com.zyd.blog.business.enums.ResponseStatus)1 GlobalFileException (com.zyd.blog.file.exception.GlobalFileException)1 ZhydException (com.zyd.blog.framework.exception.ZhydException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1