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

Function processChannelError

controller/relay.go:359–404  ·  view source on GitHub ↗
(c *gin.Context, channelError types.ChannelError, err *types.NewAPIError)

Source from the content-addressed store, hash-verified

357}
358
359func processChannelError(c *gin.Context, channelError types.ChannelError, err *types.NewAPIError) {
360 logger.LogError(c, fmt.Sprintf("channel error (channel #%d, status code: %d): %s", channelError.ChannelId, err.StatusCode, common.LocalLogPreview(err.Error())))
361 // 不要使用context获取渠道信息,异步处理时可能会出现渠道信息不一致的情况
362 // do not use context to get channel info, there may be inconsistent channel info when processing asynchronously
363 if service.ShouldDisableChannel(err) && channelError.AutoBan {
364 gopool.Go(func() {
365 service.DisableChannel(channelError, err.ErrorWithStatusCode())
366 })
367 }
368
369 if constant.ErrorLogEnabled && types.IsRecordErrorLog(err) {
370 // 保存错误日志到mysql中
371 userId := c.GetInt("id")
372 tokenName := c.GetString("token_name")
373 modelName := c.GetString("original_model")
374 tokenId := c.GetInt("token_id")
375 userGroup := c.GetString("group")
376 channelId := c.GetInt("channel_id")
377 other := make(map[string]interface{})
378 if c.Request != nil && c.Request.URL != nil {
379 other["request_path"] = c.Request.URL.Path
380 }
381 other["error_type"] = err.GetErrorType()
382 other["error_code"] = err.GetErrorCode()
383 other["status_code"] = err.StatusCode
384 other["channel_id"] = channelId
385 other["channel_name"] = c.GetString("channel_name")
386 other["channel_type"] = c.GetInt("channel_type")
387 adminInfo := make(map[string]interface{})
388 adminInfo["use_channel"] = c.GetStringSlice("use_channel")
389 isMultiKey := common.GetContextKeyBool(c, constant.ContextKeyChannelIsMultiKey)
390 if isMultiKey {
391 adminInfo["is_multi_key"] = true
392 adminInfo["multi_key_index"] = common.GetContextKeyInt(c, constant.ContextKeyChannelMultiKeyIndex)
393 }
394 service.AppendChannelAffinityAdminInfo(c, adminInfo)
395 other["admin_info"] = adminInfo
396 startTime := common.GetContextKeyTime(c, constant.ContextKeyRequestStartTime)
397 if startTime.IsZero() {
398 startTime = time.Now()
399 }
400 useTimeSeconds := int(time.Since(startTime).Seconds())
401 model.RecordErrorLog(c, userId, channelId, modelName, tokenName, err.MaskSensitiveErrorWithStatusCode(), tokenId, useTimeSeconds, common.GetContextKeyBool(c, constant.ContextKeyIsStream), userGroup, other)
402 }
403
404}
405
406func RelayMidjourney(c *gin.Context) {
407 relayInfo, err := relaycommon.GenRelayInfo(c, types.RelayFormatMjProxy, nil, nil)

Callers 3

performChannelTestsFunction · 0.85
RelayFunction · 0.85
RelayTaskFunction · 0.85

Calls 11

LogErrorFunction · 0.92
ShouldDisableChannelFunction · 0.92
DisableChannelFunction · 0.92
IsRecordErrorLogFunction · 0.92
RecordErrorLogFunction · 0.92
ErrorWithStatusCodeMethod · 0.80
GetErrorTypeMethod · 0.80
GetErrorCodeMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected