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

Function processChannelError

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

Source from the content-addressed store, hash-verified

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