Files
baiyue-firstleg/lastleg-service/src/main/java/com/baiyue/lastleg/controller/EventConsumptionExceptionHandler.java
T

22 lines
995 B
Java
Raw Normal View History

2026-09-29 18:06:18 +08:00
package com.baiyue.lastleg.controller;
import com.baiyue.common.core.api.ApiResponse;
import com.baiyue.common.event.EventProtocolException;
import com.baiyue.common.event.EventDependencyNotReadyException;
import org.slf4j.MDC;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.time.Instant;
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class EventConsumptionExceptionHandler {
@ExceptionHandler({EventProtocolException.class, EventDependencyNotReadyException.class})
public ApiResponse<Void> event(IllegalArgumentException failure) {
String code = failure instanceof EventDependencyNotReadyException ? "EVT_DEPENDENCY" : "EVT_PROTOCOL";
return new ApiResponse<>(code, failure.getMessage(), null, MDC.get("requestId"), MDC.get("traceId"), Instant.now());
}
}