sac/sf-vertx/src/main/java/com/sf/vertx/handle/ApiMockHandlerImpl.java
2024-05-24 18:54:30 +08:00

31 lines
936 B
Java

package com.sf.vertx.handle;
import com.sf.vertx.api.pojo.MockResponse;
import com.sf.vertx.enums.GatewayError;
import com.sf.vertx.exception.MockException;
import com.sf.vertx.exception.ServiceException;
import com.sf.vertx.utils.AppUtils;
import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ApiMockHandlerImpl implements ApiMockHandler {
@Override
public void handle(RoutingContext rc) {
try {
// mock
MockResponse mockResponse = AppUtils.mock(rc);
if (mockResponse != null) {
rc.fail(new MockException(mockResponse.getHttpStatus(), mockResponse.getMockResponse()));
return;
}
} catch (Exception e) {
log.error("ApiMockHandlerImpl:",e);
rc.fail(new ServiceException(GatewayError.DEFAULT_SERVICE_ERROR));
return;
}
rc.next();
}
}