Skip to content

Commit 300f271

Browse files
committed
feat: notify error detial
1 parent ce0475f commit 300f271

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

service/aiproxy/controller/relay.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func relayController(mode relaymode.Mode) (RelayController, bool) {
6060
}
6161

6262
func RelayHelper(meta *meta.Meta, c *gin.Context, relayController RelayController) (*model.ErrorWithStatusCode, bool) {
63-
err := relayController(meta, c)
64-
if err == nil {
63+
relayErr := relayController(meta, c)
64+
if relayErr == nil {
6565
if _, _, err := monitor.AddRequest(
6666
context.Background(),
6767
meta.OriginModel,
@@ -72,7 +72,7 @@ func RelayHelper(meta *meta.Meta, c *gin.Context, relayController RelayControlle
7272
}
7373
return nil, false
7474
}
75-
if shouldErrorMonitor(err.StatusCode) {
75+
if shouldErrorMonitor(relayErr.StatusCode) {
7676
beyondThreshold, autoBanned, err := monitor.AddRequest(
7777
context.Background(),
7878
meta.OriginModel,
@@ -88,17 +88,19 @@ func RelayHelper(meta *meta.Meta, c *gin.Context, relayController RelayControlle
8888
time.Minute,
8989
fmt.Sprintf("channel[%d] %s(%d) model %s is auto banned",
9090
meta.Channel.Type, meta.Channel.Name, meta.Channel.ID, meta.OriginModel),
91-
"autoBanned")
91+
"last error detail: "+relayErr.JSONOrEmpty(),
92+
)
9293
} else if beyondThreshold {
9394
notify.WarnThrottle(
9495
fmt.Sprintf("beyondThreshold:%d:%s", meta.Channel.ID, meta.OriginModel),
9596
time.Minute,
9697
fmt.Sprintf("channel[%d] %s(%d) model %s error rate is beyond threshold",
9798
meta.Channel.Type, meta.Channel.Name, meta.Channel.ID, meta.OriginModel),
98-
"beyondThreshold")
99+
"last error detail: "+relayErr.JSONOrEmpty(),
100+
)
99101
}
100102
}
101-
return err, shouldRetry(c, err.StatusCode)
103+
return relayErr, shouldRetry(c, relayErr.StatusCode)
102104
}
103105

104106
func filterChannels(channels []*dbmodel.Channel, ignoreChannel ...int) []*dbmodel.Channel {

service/aiproxy/relay/model/misc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ func (e *Error) JSONOrEmpty() string {
3434
}
3535

3636
type ErrorWithStatusCode struct {
37-
Error Error `json:"error"`
37+
Error Error `json:"error,omitempty"`
3838
StatusCode int `json:"-"`
3939
}
4040

4141
func (e *ErrorWithStatusCode) JSONOrEmpty() string {
42-
if e.Error.IsEmpty() {
42+
if e.StatusCode == 0 && e.Error.IsEmpty() {
4343
return ""
4444
}
45-
jsonBuf, err := sonic.Marshal(e)
45+
jsonBuf, err := sonic.MarshalString(e)
4646
if err != nil {
4747
return ""
4848
}
49-
return conv.BytesToString(jsonBuf)
49+
return jsonBuf
5050
}

0 commit comments

Comments
 (0)