|
@@ -93,12 +93,6 @@ func ParseResponse(input any) (*Response, error) {
|
|
|
return nil, fmt.Errorf("unmarshal response: %w", err)
|
|
return nil, fmt.Errorf("unmarshal response: %w", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if resp.ID == nil {
|
|
|
|
|
- if resp.Error == nil || resp.Error.Code != ErrParse {
|
|
|
|
|
- return nil, errors.New(`response must contain an "id" field`)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if resp.Error == nil && resp.Result == nil {
|
|
if resp.Error == nil && resp.Result == nil {
|
|
|
return nil, errors.New(`response must contain either "result" or "error" field`)
|
|
return nil, errors.New(`response must contain either "result" or "error" field`)
|
|
|
}
|
|
}
|
|
@@ -107,6 +101,14 @@ func ParseResponse(input any) (*Response, error) {
|
|
|
return nil, errors.New(`response can't contain both "result" and "error" field`)
|
|
return nil, errors.New(`response can't contain both "result" and "error" field`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if resp.Error != nil && resp.ID == nil && resp.Error.Code != ErrParse {
|
|
|
|
|
+ return nil, errors.New(`"error" must contain an "id" field`)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if resp.Result != nil && resp.ID == nil {
|
|
|
|
|
+ return nil, errors.New(`"result" must contain an "id" field`)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return &resp, nil
|
|
return &resp, nil
|
|
|
}
|
|
}
|
|
|
|
|
|