int ConnectNode::getErrorCodeFromMsg()

in nlsCppSdk/transport/connectNode.cpp [2684:2734]


int ConnectNode::getErrorCodeFromMsg(const char *msg) {
  int code = DefaultErrorCode;

  try {
    Json::Reader reader;
    Json::Value root(Json::objectValue);

    // parse json if existent
    if (reader.parse(msg, root)) {
      if (!root["header"].isNull() && root["header"].isObject()) {
        Json::Value head = root["header"];
        if (!head["status"].isNull() && head["status"].isInt()) {
          code = head["status"].asInt();
        }
      }
    } else {
      if (strstr(msg, "return of SSL_read:")) {
        if (strstr(msg, "error:00000000:lib(0):func(0):reason(0)") ||
            strstr(msg, "shutdown while in init")) {
          code = DefaultErrorCode;
        }
      } else if (strstr(msg, "ACCESS_DENIED")) {
        if (strstr(msg, "The token")) {
          if (strstr(msg, "has expired")) {
            code = TokenHasExpired;
          } else if (strstr(msg, "is invalid")) {
            code = TokenIsInvalid;
          }
        } else if (strstr(msg, "No privilege to this voice")) {
          code = NoPrivilegeToVoice;
        } else if (strstr(msg, "Missing authorization header")) {
          code = MissAuthHeader;
        }
      } else if (strstr(msg, "Got bad status")) {
        if (strstr(msg, "403 Forbidden")) {
          code = HttpGotBadStatusWith403;
        }
      } else if (strstr(msg, "Operation now in progress")) {
        code = OpNowInProgress;
      } else if (strstr(msg, "Broken pipe")) {
        code = BrokenPipe;
      } else if (strstr(msg, "connect failed")) {
        code = SysConnectFailed;
      }
    }
  } catch (const std::exception &e) {
    LOG_ERROR("Json failed: %s", e.what());
    return code;
  }
  return code;
}