mirror of
				https://github.com/linux-do/new-api.git
				synced 2025-11-04 05:13:41 +08:00 
			
		
		
		
	feat: 避免暴露内部错误
This commit is contained in:
		@@ -28,13 +28,11 @@ func MidjourneyErrorWithStatusCodeWrapper(code int, desc string, statusCode int)
 | 
				
			|||||||
// OpenAIErrorWrapper wraps an error into an OpenAIErrorWithStatusCode
 | 
					// OpenAIErrorWrapper wraps an error into an OpenAIErrorWithStatusCode
 | 
				
			||||||
func OpenAIErrorWrapper(err error, code string, statusCode int) *dto.OpenAIErrorWithStatusCode {
 | 
					func OpenAIErrorWrapper(err error, code string, statusCode int) *dto.OpenAIErrorWithStatusCode {
 | 
				
			||||||
	text := err.Error()
 | 
						text := err.Error()
 | 
				
			||||||
	// 定义一个正则表达式匹配URL
 | 
						lowerText := strings.ToLower(text)
 | 
				
			||||||
	if strings.Contains(text, "Post") || strings.Contains(text, "dial") {
 | 
						if strings.Contains(lowerText, "post") || strings.Contains(lowerText, "dial") || strings.Contains(lowerText, "http") {
 | 
				
			||||||
		common.SysLog(fmt.Sprintf("error: %s", text))
 | 
							common.SysLog(fmt.Sprintf("error: %s", text))
 | 
				
			||||||
		text = "请求上游地址失败"
 | 
							text = "请求上游地址失败"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//避免暴露内部错误
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	openAIError := dto.OpenAIError{
 | 
						openAIError := dto.OpenAIError{
 | 
				
			||||||
		Message: text,
 | 
							Message: text,
 | 
				
			||||||
		Type:    "new_api_error",
 | 
							Type:    "new_api_error",
 | 
				
			||||||
@@ -113,14 +111,12 @@ func TaskErrorWrapperLocal(err error, code string, statusCode int) *dto.TaskErro
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TaskErrorWrapper(err error, code string, statusCode int) *dto.TaskError {
 | 
					func TaskErrorWrapper(err error, code string, statusCode int) *dto.TaskError {
 | 
				
			||||||
	text := err.Error()
 | 
						text := err.Error()
 | 
				
			||||||
 | 
						lowerText := strings.ToLower(text)
 | 
				
			||||||
	// 定义一个正则表达式匹配URL
 | 
						if strings.Contains(lowerText, "post") || strings.Contains(lowerText, "dial") || strings.Contains(lowerText, "http") {
 | 
				
			||||||
	if strings.Contains(text, "Post") || strings.Contains(text, "dial") {
 | 
					 | 
				
			||||||
		common.SysLog(fmt.Sprintf("error: %s", text))
 | 
							common.SysLog(fmt.Sprintf("error: %s", text))
 | 
				
			||||||
		text = "请求上游地址失败"
 | 
							text = "请求上游地址失败"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//避免暴露内部错误
 | 
						//避免暴露内部错误
 | 
				
			||||||
 | 
					 | 
				
			||||||
	taskError := &dto.TaskError{
 | 
						taskError := &dto.TaskError{
 | 
				
			||||||
		Code:       code,
 | 
							Code:       code,
 | 
				
			||||||
		Message:    text,
 | 
							Message:    text,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user