feat: check claude's error response

This commit is contained in:
JustSong 2024-03-10 20:39:55 +08:00
parent 796be42487
commit 1ea598c773

View File

@ -27,7 +27,16 @@ func ShouldDisableChannel(err *relaymodel.Error, statusCode int) bool {
if statusCode == http.StatusUnauthorized { if statusCode == http.StatusUnauthorized {
return true 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 true
} }
return false return false
@ -101,6 +110,9 @@ func RelayErrorHandler(resp *http.Response) (ErrorWithStatusCode *relaymodel.Err
if err != nil { if err != nil {
return return
} }
if config.DebugEnabled {
logger.SysLog(fmt.Sprintf("error happened, status code: %d, response: \n%s", resp.StatusCode, string(responseBody)))
}
err = resp.Body.Close() err = resp.Body.Close()
if err != nil { if err != nil {
return return