package com.talentcard.server.config; import com.talentcard.server.business.admin.BenefitServiceCouponAdminController; import com.talentcard.server.common.ApiResponse; import com.talentcard.server.common.BusinessException; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @Order(Ordered.HIGHEST_PRECEDENCE) @RestControllerAdvice(assignableTypes = BenefitServiceCouponAdminController.class) public class BenefitServiceCouponExceptionHandler { @ExceptionHandler(BusinessException.class) public ResponseEntity> business(BusinessException exception) { return error(exception.getMessage()); } @ExceptionHandler(Exception.class) public ResponseEntity> exception(Exception exception) { return error("优惠券配置处理失败"); } private ResponseEntity> error(String message) { String fallback = "优惠券配置处理失败"; return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(ApiResponse.failure(500, message == null || message.isBlank() ? fallback : message)); } }