Search in sources :

Example 1 with ErrorCode

use of com.tencent.polaris.api.exception.ErrorCode in project polaris-java by polarismesh.

the class SpecStreamClient method validMessage.

/**
 * 检查该应答是否合法,不合法则走异常流程
 *
 * @param response 服务端应答
 * @return 合法返回true,否则返回false
 */
private ValidResult validMessage(ResponseProto.DiscoverResponse response) {
    ErrorCode errorCode = ErrorCode.Success;
    if (response.hasCode()) {
        errorCode = ServerCodes.convertServerErrorToRpcError(response.getCode().getValue());
    }
    ServiceProto.Service service;
    if (CollectionUtils.isNotEmpty(response.getServicesList())) {
        service = response.getServicesList().get(0);
    } else {
        service = response.getService();
    }
    if (null == service || StringUtils.isEmpty(service.getNamespace().getValue()) || StringUtils.isEmpty(service.getName().getValue())) {
        return new ValidResult(null, ErrorCode.INVALID_SERVER_RESPONSE, "service is empty, response text is " + response.toString());
    }
    EventType eventType = GrpcUtil.buildEventType(response.getType());
    if (eventType == EventType.UNKNOWN) {
        return new ValidResult(null, ErrorCode.INVALID_SERVER_RESPONSE, "invalid event type " + response.getType());
    }
    ServiceEventKey serviceEventKey = new ServiceEventKey(new ServiceKey(service.getNamespace().getValue(), service.getName().getValue()), eventType);
    if (errorCode == ErrorCode.SERVER_ERROR) {
        // 返回了500错误
        return new ValidResult(serviceEventKey, errorCode, "invalid event type " + response.getType());
    }
    return new ValidResult(serviceEventKey, ErrorCode.Success, "");
}
Also used : EventType(com.tencent.polaris.api.pojo.ServiceEventKey.EventType) ServiceKey(com.tencent.polaris.api.pojo.ServiceKey) ServiceEventKey(com.tencent.polaris.api.pojo.ServiceEventKey) ErrorCode(com.tencent.polaris.api.exception.ErrorCode) ServiceProto(com.tencent.polaris.client.pb.ServiceProto)

Aggregations

ErrorCode (com.tencent.polaris.api.exception.ErrorCode)1 ServiceEventKey (com.tencent.polaris.api.pojo.ServiceEventKey)1 EventType (com.tencent.polaris.api.pojo.ServiceEventKey.EventType)1 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)1 ServiceProto (com.tencent.polaris.client.pb.ServiceProto)1