diff --git a/channels/shangwutong/internal/swt/client.go b/channels/shangwutong/internal/swt/client.go index 3228bd58..3294c28b 100644 --- a/channels/shangwutong/internal/swt/client.go +++ b/channels/shangwutong/internal/swt/client.go @@ -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) diff --git a/channels/shangwutong/internal/swt/client_test.go b/channels/shangwutong/internal/swt/client_test.go index 02e8a851..59986224 100644 --- a/channels/shangwutong/internal/swt/client_test.go +++ b/channels/shangwutong/internal/swt/client_test.go @@ -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 {