MCPcopy Create free account
hub / github.com/QuantumNous/new-api / detectErrorMessageFromJSONBytes

Function detectErrorMessageFromJSONBytes

controller/channel-test.go:666–693  ·  view source on GitHub ↗
(jsonBytes []byte)

Source from the content-addressed store, hash-verified

664}
665
666func detectErrorMessageFromJSONBytes(jsonBytes []byte) string {
667 if len(jsonBytes) == 0 {
668 return ""
669 }
670 if jsonBytes[0] != '{' && jsonBytes[0] != '[' {
671 return ""
672 }
673 errVal := gjson.GetBytes(jsonBytes, "error")
674 if !errVal.Exists() || errVal.Type == gjson.Null {
675 return ""
676 }
677
678 message := gjson.GetBytes(jsonBytes, "error.message").String()
679 if message == "" {
680 message = gjson.GetBytes(jsonBytes, "error.error.message").String()
681 }
682 if message == "" && errVal.Type == gjson.String {
683 message = errVal.String()
684 }
685 if message == "" {
686 message = errVal.Raw
687 }
688 message = strings.TrimSpace(message)
689 if message == "" {
690 return "upstream returned error payload"
691 }
692 return message
693}
694
695func buildTestRequest(model string, endpointType string, channel *model.Channel, isStream bool) dto.Request {
696 testResponsesInput := json.RawMessage(`[{"role":"user","content":"hi"}]`)

Callers 1

Calls 2

ExistsMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected