H-171: require explicit Shangwutong send success (#29)
Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user