H-171: require explicit Shangwutong send success (#29)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-15 12:18:55 +08:00
committed by GitHub
co-authored by rogee
parent 2d1b9ab5a7
commit 992c9bf0e9
2 changed files with 6 additions and 3 deletions
+4 -3
View File
@@ -198,13 +198,14 @@ func (c *Client) sendHTML(ctx context.Context, session Session, sid, content, op
return SendResult{}, &Error{Operation: operation, Code: "network_error", Retryable: true, Err: err}
}
status := strings.TrimSpace(response.Header.Get("r"))
if !strings.EqualFold(status, "ok") {
if protocolError := strings.TrimSpace(response.Header.Get("error")); protocolError != "" {
successful := strings.EqualFold(status, "ok")
if !successful {
if protocolError := strings.TrimSpace(response.Header.Get("error")); protocolError != "" && !strings.EqualFold(protocolError, "ok") {
status = protocolError
}
}
result := SendResult{Status: status, Body: body}
if strings.EqualFold(status, "ok") {
if successful {
return result, nil
}
code := normalizeCode(status)
@@ -77,6 +77,8 @@ func TestClientSendTextClassifiesProtocolStatus(t *testing.T) {
{name: "explicit failure", status: "failed", wantCode: "failed"},
{name: "error header", protocolError: "state err", wantCode: "state_err"},
{name: "retryable error", protocolError: "server err", wantCode: "server_err", wantRetryable: true},
{name: "error cannot override failure", status: "failed", protocolError: "ok", wantCode: "failed"},
{name: "error cannot supply success", protocolError: "ok", wantCode: "missing_status"},
{name: "missing status", wantCode: "missing_status"},
}
for _, test := range tests {