MCPcopy
hub / github.com/QuantumNous/new-api / auditResponseSuccess

Function auditResponseSuccess

middleware/audit.go:192–206  ·  view source on GitHub ↗

auditResponseSuccess 依据 HTTP 状态码与响应体推断操作是否成功。 优先解析响应 JSON 中的 success 字段;无法解析时退回到状态码判断。

(status int, body []byte)

Source from the content-addressed store, hash-verified

190// auditResponseSuccess 依据 HTTP 状态码与响应体推断操作是否成功。
191// 优先解析响应 JSON 中的 success 字段;无法解析时退回到状态码判断。
192func auditResponseSuccess(status int, body []byte) bool {
193 if status >= 400 {
194 return false
195 }
196 trimmed := bytes.TrimSpace(body)
197 if len(trimmed) > 0 && trimmed[0] == '{' {
198 var resp struct {
199 Success *bool `json:"success"`
200 }
201 if err := common.Unmarshal(trimmed, &resp); err == nil && resp.Success != nil {
202 return *resp.Success
203 }
204 }
205 return status < 400
206}

Callers 1

finishAdminAuditFunction · 0.85

Calls 1

UnmarshalFunction · 0.92

Tested by

no test coverage detected