Parcourir la source

修复优化代码后,json rpc 2.0和老版本不兼容的问题

niujiuru il y a 1 semaine
Parent
commit
7c933737a9

BIN
package/rtu_linux_modules_1.0.0.1.tar.gz


BIN
package/yfkj_ssh_client_1.0.0.1.tar.gz


+ 4 - 4
utils/jsonrpc2/rpc.go

@@ -125,9 +125,9 @@ func ParseResponse(input any) (*Response, error) {
 
 	// 情况 4:错误时的应答 → 必须有id&且不能空
 	if resp.Error != nil && resp.Error.Code == ErrParse { // 当发生解析错误时, "id"必须为: nil
-		if resp.ID != nil {
+		/*if resp.ID != nil { // 虽然更符合规范, 但老版本请求有的会返回ErrParse, 为了兼容, 暂不启用
 			return nil, errors.New(`"id" must be null for parse error`)
-		}
+		}*/
 		return &resp, nil
 	}
 
@@ -240,9 +240,9 @@ func BuildError(req *Request, code ErrCode, message string) *Response {
 		id = req.ID
 	}
 
-	if code == ErrParse {
+	/*if code == ErrParse {
 		id = nil
-	}
+	}*/ // 虽然更符合规范, 但老版本请求有的会返回ErrParse, 为了兼容, 暂不启用
 
 	emsg := message
 	if emsg == "" {