|
|
@ -0,0 +1,24 @@ |
|
|
|
package com.iflytop.gd.system.handler; |
|
|
|
|
|
|
|
import com.iflytop.gd.system.common.exception.AppException; |
|
|
|
import com.iflytop.gd.system.common.result.Result; |
|
|
|
import com.iflytop.gd.system.common.result.ResultCode; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler; |
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@RestControllerAdvice |
|
|
|
public class GlobalExceptionHandler { |
|
|
|
|
|
|
|
@ExceptionHandler(Exception.class) |
|
|
|
public Result<?> handleException(Exception ex) { |
|
|
|
if (ex instanceof AppException ae) { |
|
|
|
log.warn("AppException:", ae); |
|
|
|
return Result.failed(ae.getResultCode()); |
|
|
|
} |
|
|
|
log.error("Unhandled exception:", ex); |
|
|
|
return Result.failed(ResultCode.SYSTEM_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
} |