| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- namespace OASystem.API.OAMethodLib.TokenHubAI.Models;
- /// <summary>
- /// TokenHub 业务错误码常量
- /// </summary>
- public static class TokenHubErrorCode
- {
- // 400 系列 - 客户端请求错误
- public const string InvalidRequest = "400001";
- public const string InvalidParameter = "400002";
- public const string InputTooLong = "400003";
- public const string ModelNotFound = "400004";
- public const string UnsupportedModel = "400005";
- public const string UnsupportedFormat = "400006";
- // 401 系列 - 认证错误
- public const string Unauthorized = "401001";
- public const string InvalidApiKey = "401002";
- public const string ApiKeyExpired = "401003";
- public const string ApiKeyDisabled = "401004";
- public const string SignatureInvalid = "401005";
- public const string InvalidEndpoint = "401006";
- // 402 系列 - 计费错误
- public const string NoFreePackage = "401007";
- public const string FreeQuotaExhausted = "401008";
- // 403 系列 - 权限错误
- public const string PermissionDenied = "403001";
- public const string ModelAccessDenied = "403002";
- public const string AccountBlocked = "403003";
- public const string InsufficientBalance = "403004";
- public const string IPNotAllowed = "403005";
- // 429 系列 - 限流错误
- public const string RateLimitExceeded = "429001";
- public const string RPMLimitExceeded = "429002";
- public const string TPMLimitExceeded = "429003";
- public const string TPDLimitExceeded = "429004";
- public const string ConcurrencyLimitExceeded = "429005";
- // 451 - 内容安全
- public const string ContentFiltered = "451001";
- // 499 - 请求取消
- public const string RequestCanceled = "499001";
- // 410 - 会话过期
- public const string SessionExpired = "410001";
- // 500 系列 - 服务端错误
- public const string InternalError = "500001";
- public const string UpstreamError = "502001";
- public const string ServiceUnavailable = "503001";
- public const string GatewayTimeout = "504001";
- /// <summary>
- /// 判断是否为客户端错误(需修改请求)
- /// </summary>
- public static bool IsClientError(string? code)
- {
- return code switch
- {
- InvalidRequest or InvalidParameter or InputTooLong or
- ModelNotFound or UnsupportedModel or UnsupportedFormat or
- Unauthorized or InvalidApiKey or ApiKeyExpired or
- ApiKeyDisabled or SignatureInvalid or InvalidEndpoint or
- PermissionDenied or ModelAccessDenied or IPNotAllowed or
- ContentFiltered => true,
- _ => false
- };
- }
- /// <summary>
- /// 判断是否为计费相关错误
- /// </summary>
- public static bool IsBillingError(string? code)
- {
- return code switch
- {
- NoFreePackage or FreeQuotaExhausted or
- InsufficientBalance or AccountBlocked => true,
- _ => false
- };
- }
- /// <summary>
- /// 判断是否为限流错误
- /// </summary>
- public static bool IsRateLimitError(string? code)
- {
- return code switch
- {
- RateLimitExceeded or RPMLimitExceeded or
- TPMLimitExceeded or TPDLimitExceeded or
- ConcurrencyLimitExceeded => true,
- _ => false
- };
- }
- }
|