package com.talentcard.server.config;
|
|
import com.talentcard.server.business.admin.DependentCardApplyAdminController;
|
import com.talentcard.server.common.ApiResponse;
|
import com.talentcard.server.common.BusinessException;
|
import jakarta.validation.ConstraintViolationException;
|
import org.springframework.core.Ordered;
|
import org.springframework.core.annotation.Order;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
import org.springframework.validation.BindException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
@RestControllerAdvice(assignableTypes = DependentCardApplyAdminController.class)
|
public class DependentCardApplyAdminExceptionHandler {
|
@ExceptionHandler(BusinessException.class)
|
public ResponseEntity<ApiResponse<Void>> handleBusinessException(BusinessException exception) {
|
return error(exception.getMessage());
|
}
|
|
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class,
|
ConstraintViolationException.class, HttpMessageNotReadableException.class})
|
public ResponseEntity<ApiResponse<Void>> handleRequestException(Exception exception) {
|
return error("审核参数不正确");
|
}
|
|
@ExceptionHandler(Exception.class)
|
public ResponseEntity<ApiResponse<Void>> handleException(Exception exception) {
|
return error("家属附属卡申请处理失败");
|
}
|
|
private ResponseEntity<ApiResponse<Void>> error(String message) {
|
String fallback = "家属附属卡申请处理失败";
|
String safeMessage = message == null || message.isBlank() ? fallback : message;
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
.body(ApiResponse.failure(500, safeMessage));
|
}
|
}
|