mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-10-31 13:53:41 +08:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			v0.6.2-alp
			...
			v0.6.2-alp
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 358920c858 | ||
|  | 1ea598c773 | 
| @@ -13,7 +13,7 @@ import ( | ||||
| type Channel struct { | ||||
| 	Id                 int     `json:"id"` | ||||
| 	Type               int     `json:"type" gorm:"default:0"` | ||||
| 	Key                string  `json:"key" gorm:"not null;index"` | ||||
| 	Key                string  `json:"key" gorm:"type:text"` | ||||
| 	Status             int     `json:"status" gorm:"default:1"` | ||||
| 	Name               string  `json:"name" gorm:"index"` | ||||
| 	Weight             *uint   `json:"weight" gorm:"default:0"` | ||||
| @@ -47,11 +47,7 @@ func GetAllChannels(startIdx int, num int, scope string) ([]*Channel, error) { | ||||
| } | ||||
|  | ||||
| func SearchChannels(keyword string) (channels []*Channel, err error) { | ||||
| 	keyCol := "`key`" | ||||
| 	if common.UsingPostgreSQL { | ||||
| 		keyCol = `"key"` | ||||
| 	} | ||||
| 	err = DB.Omit("key").Where("id = ? or name LIKE ? or "+keyCol+" = ?", helper.String2Int(keyword), keyword+"%", keyword).Find(&channels).Error | ||||
| 	err = DB.Omit("key").Where("id = ? or name LIKE ?", helper.String2Int(keyword), keyword+"%").Find(&channels).Error | ||||
| 	return channels, err | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -27,7 +27,16 @@ func ShouldDisableChannel(err *relaymodel.Error, statusCode int) bool { | ||||
| 	if statusCode == http.StatusUnauthorized { | ||||
| 		return true | ||||
| 	} | ||||
| 	if err.Type == "insufficient_quota" || err.Code == "invalid_api_key" || err.Code == "account_deactivated" { | ||||
| 	switch err.Type { | ||||
| 	case "insufficient_quota": | ||||
| 		return true | ||||
| 	// https://docs.anthropic.com/claude/reference/errors | ||||
| 	case "authentication_error": | ||||
| 		return true | ||||
| 	case "permission_error": | ||||
| 		return true | ||||
| 	} | ||||
| 	if err.Code == "invalid_api_key" || err.Code == "account_deactivated" { | ||||
| 		return true | ||||
| 	} | ||||
| 	return false | ||||
| @@ -101,6 +110,9 @@ func RelayErrorHandler(resp *http.Response) (ErrorWithStatusCode *relaymodel.Err | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	if config.DebugEnabled { | ||||
| 		logger.SysLog(fmt.Sprintf("error happened, status code: %d, response: \n%s", resp.StatusCode, string(responseBody))) | ||||
| 	} | ||||
| 	err = resp.Body.Close() | ||||
| 	if err != nil { | ||||
| 		return | ||||
|   | ||||
		Reference in New Issue
	
	Block a user