mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-09-20 17:07:59 +00:00
refactor: unify oneLineStr/oneLine into types.OneLine
provider.oneLineStr and gateway.oneLine had byte-identical bodies (flatten whitespace + cap length). Move the single implementation into the types package, which both layers already depend on, and delete both locals.
This commit is contained in:
@ -929,13 +929,6 @@ func errorOnlyChunk(ck types.UnifiedChunk) bool {
|
||||
ck.ReasoningContent == "" && ck.Usage == nil
|
||||
}
|
||||
|
||||
func oneLineStr(s string, n int) string {
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
if len(s) > n {
|
||||
s = s[:n] + "..."
|
||||
}
|
||||
return s
|
||||
}
|
||||
// apiErrReason builds the client-facing reason for a non-200 upstream
|
||||
// response: the adapter's optional transform_error hook wins (per-source
|
||||
// protocol knowledge lives in Lua), otherwise clients get a uniform
|
||||
@ -943,11 +936,11 @@ func oneLineStr(s string, n int) string {
|
||||
func (p *Provider) apiErrReason(status int, raw string) string {
|
||||
if reason, ok, err := p.vm.TransformError(p.adapter, status, raw); err == nil && ok {
|
||||
if trimmed := strings.TrimSpace(reason); trimmed != "" {
|
||||
return fmt.Sprintf("api error %d: %s", status, oneLineStr(trimmed, 200))
|
||||
return fmt.Sprintf("api error %d: %s", status, types.OneLine(trimmed, 200))
|
||||
}
|
||||
}
|
||||
log.Printf("[provider] unhandled upstream error body (adapter %q lacks transform_error): status=%d body=%.300s",
|
||||
p.adapter, status, oneLineStr(raw, 300))
|
||||
p.adapter, status, types.OneLine(raw, 300))
|
||||
return fmt.Sprintf("api error %d: unknown error", status)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user