2026-04-09 13:21:06 +08:00
|
|
|
package com.label.common.exception;
|
|
|
|
|
|
|
|
|
|
import com.label.common.result.Result;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestControllerAdvice
|
|
|
|
|
public class GlobalExceptionHandler {
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(BusinessException.class)
|
|
|
|
|
public ResponseEntity<Result<?>> handleBusinessException(BusinessException e) {
|
|
|
|
|
log.warn("业务异常: code={}, message={}", e.getCode(), e.getMessage());
|
|
|
|
|
return ResponseEntity
|
2026-04-14 16:33:34 +08:00
|
|
|
.status(e.getHttpStatus())
|
|
|
|
|
.body(Result.failure(e.getCode(), e.getMessage()));
|
2026-04-09 15:16:49 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-09 13:21:06 +08:00
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
|
public ResponseEntity<Result<?>> handleException(Exception e) {
|
|
|
|
|
log.error("系统异常", e);
|
|
|
|
|
return ResponseEntity
|
2026-04-14 16:33:34 +08:00
|
|
|
.internalServerError()
|
|
|
|
|
.body(Result.failure("INTERNAL_ERROR", "系统内部错误"));
|
2026-04-09 13:21:06 +08:00
|
|
|
}
|
|
|
|
|
}
|