sac/sf-vertx/src/main/java/com/sf/vertx/handle/ApiMockHandlerImpl.java

31 lines
936 B
Java
Raw Normal View History

2024-05-21 14:17:59 +08:00
package com.sf.vertx.handle;
import com.sf.vertx.api.pojo.MockResponse;
2024-05-24 18:54:30 +08:00
import com.sf.vertx.enums.GatewayError;
import com.sf.vertx.exception.MockException;
import com.sf.vertx.exception.ServiceException;
import com.sf.vertx.utils.AppUtils;
2024-05-21 14:17:59 +08:00
import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ApiMockHandlerImpl implements ApiMockHandler {
2024-05-21 17:39:43 +08:00
@Override
public void handle(RoutingContext rc) {
try {
// mock
2024-05-24 18:54:30 +08:00
MockResponse mockResponse = AppUtils.mock(rc);
2024-05-21 17:39:43 +08:00
if (mockResponse != null) {
rc.fail(new MockException(mockResponse.getHttpStatus(), mockResponse.getMockResponse()));
return;
}
} catch (Exception e) {
2024-05-24 18:54:30 +08:00
log.error("ApiMockHandlerImpl:",e);
rc.fail(new ServiceException(GatewayError.DEFAULT_SERVICE_ERROR));
2024-05-21 17:39:43 +08:00
return;
}
rc.next();
}
2024-05-21 14:17:59 +08:00
}