Documentation
¶
Overview ¶
Package code defines shared error codes used across the iam-contracts services.
错误码按照"通用能力 + 业务模块"进行分层管理,方便在系统中快速定位并统一处理。 每个文件代表一个模块或域的错误码定义:
- base.go :平台级非业务错误码(如绑定、校验、数据库、编码等),范围:100001~100999
- identity.go :基础用户及身份档案/监护等领域错误码,范围:101000~101999
- authn.go :认证(Authentication)相关所有错误码(包含 JWKS),范围:102000~102999
- authz.go :授权(Authorization)相关所有错误码,范围:103000~103999
- 其他错误码 :预留范围:104000~104999
约定:
- 错误码统一通过 pkg/errors.WithCode / WrapC 产出,确保能够被统一解析。
- 不同模块的错误码区间互不重叠,便于排查(详见各文件中的常量定义)。
- 错误码命名遵循 Err + 模块 + 问题描述 的形式,例如 ErrUserNotFound。
使用示例:
return errors.WithCode(code.ErrUserNotFound, "user(%s) not found", userID)
Index ¶
Constants ¶
const ( // ErrUnauthenticated - 401: Authentication failed. ErrUnauthenticated = 102000 // ErrInvalidCredentials - 401: Invalid credentials. ErrInvalidCredentials = 102001 // ErrTokenInvalid - 401: Token invalid. ErrTokenInvalid = 102002 // ErrEncrypt - 401: Error occurred while encrypting the user password. ErrEncrypt = 102003 // ErrSignatureInvalid - 401: Signature is invalid. ErrSignatureInvalid = 102004 // ErrExpired - 401: Token expired. ErrExpired = 102005 // ErrInvalidAuthHeader - 401: Invalid authorization header. ErrInvalidAuthHeader = 102006 // ErrMissingHeader - 401: The `Authorization` header was empty. ErrMissingHeader = 102007 // ErrPasswordIncorrect - 401: Password was incorrect. ErrPasswordIncorrect = 102008 // ErrUserNotRegistered - 401: User not registered. ErrUserNotRegistered = 102009 )
Authn: 基础认证错误 (102000~102099).
const ( // ErrInvalidKid - 400: Invalid kid: kid cannot be empty. ErrInvalidKid = 102100 // ErrInvalidJWK - 400: Invalid JWK: kty cannot be empty. ErrInvalidJWK = 102101 // ErrInvalidJWKUse - 400: Invalid JWK: use must be 'sig'. ErrInvalidJWKUse = 102102 // ErrInvalidJWKAlg - 400: Invalid JWK: alg cannot be empty. ErrInvalidJWKAlg = 102103 // ErrKidMismatch - 400: Kid mismatch: key.Kid and JWK.Kid must be equal. ErrKidMismatch = 102104 // ErrUnsupportedKty - 400: Unsupported key type. ErrUnsupportedKty = 102105 // ErrMissingRSAParams - 400: Missing RSA parameters: n and e are required. ErrMissingRSAParams = 102106 // ErrMissingECParams - 400: Missing EC parameters: crv, x, y are required. ErrMissingECParams = 102107 // ErrMissingOKPParams - 400: Missing OKP parameters: crv, x are required. ErrMissingOKPParams = 102108 // ErrInvalidStateTransition - 400: Invalid key state transition. ErrInvalidStateTransition = 102109 // ErrInvalidTimeRange - 400: Invalid time range: NotAfter must be after NotBefore. ErrInvalidTimeRange = 102110 // ErrEmptyJWKS - 400: JWKS cannot be empty. ErrEmptyJWKS = 102111 // ErrInvalidRotationInterval - 400: Rotation interval must be positive. ErrInvalidRotationInterval = 102112 // ErrInvalidGracePeriod - 400: Grace period must be positive. ErrInvalidGracePeriod = 102113 // ErrInvalidMaxKeys - 400: Max keys must be at least 2. ErrInvalidMaxKeys = 102114 // ErrGracePeriodTooLong - 400: Grace period must be shorter than rotation interval. ErrGracePeriodTooLong = 102115 // ErrKeyNotFound - 404: Key not found. ErrKeyNotFound = 102116 // ErrNoActiveKey - 404: No active key available. ErrNoActiveKey = 102117 // ErrKeyAlreadyExists - 409: Key with this kid already exists. ErrKeyAlreadyExists = 102118 )
Authn: JWKS 密钥管理相关错误 (102100~102199).
const ( ErrAccountExists = 102200 ErrExternalExists = 102201 ErrNotFoundAccount = 102202 ErrUniqueIDExists = 102203 ErrInvalidUniqueID = 102204 )
Authn: 账号相关错误码 (102200~102299).
const ( ErrCredentialExists = 102300 ErrCredentialNotFound = 102301 ErrCredentialLocked = 102302 ErrCredentialExpired = 102303 ErrCredentialDisabled = 102304 ErrInvalidCredential = 102305 ErrCredentialNotUsable = 102306 )
Authn: 凭据相关错误码 (102300~102399).
const ( ErrAuthenticationFailed = 102400 ErrOTPInvalid = 102401 ErrStateMismatch = 102402 ErrIDPExchangeFailed = 102403 ErrNoBinding = 102404 )
Authn: 认证流程相关错误码 (102400~102499).
const ( ErrUnauthorized = 103000 // ErrPermissionDenied - 403: Permission denied. ErrPermissionDenied = 103001 )
Authz: 基础权限错误 (103000~103099).
const ( // ErrRoleNotFound - 404: Role not found. ErrRoleNotFound = 103100 // ErrRoleAlreadyExists - 409: Role already exists. ErrRoleAlreadyExists = 103101 )
Authz: 角色相关错误 (103100~103199).
const ( // ErrResourceNotFound - 404: Resource not found. ErrResourceNotFound = 103200 // ErrResourceAlreadyExists - 409: Resource already exists. ErrResourceAlreadyExists = 103201 // ErrInvalidAction - 400: Invalid action for resource. ErrInvalidAction = 103202 )
Authz: 资源相关错误 (103200~103299).
const ( // ErrAssignmentNotFound - 404: Assignment not found. ErrAssignmentNotFound = 103300 // ErrAssignmentAlreadyExists - 409: Assignment already exists. ErrAssignmentAlreadyExists = 103301 )
Authz: 赋权相关错误 (103300~103399).
const ( // ErrPolicyVersionNotFound - 404: Policy version not found. ErrPolicyVersionNotFound = 103400 // ErrPolicyVersionAlreadyExists - 409: Policy version already exists. ErrPolicyVersionAlreadyExists = 103401 )
Authz: 策略相关错误 (103400~103499).
const ( // ErrSuccess - 200: OK. ErrSuccess = 100001 // ErrUnknown - 500: Internal server error. ErrUnknown = 100002 // ErrBind - 400: Error occurred while binding the request body to the struct. ErrBind = 100003 // ErrValidation - 400: Validation failed. ErrValidation = 100004 // ErrInvalidArgument - 400: Invalid argument. ErrInvalidArgument = 100005 // ErrPageNotFound - 404: Page not found. ErrPageNotFound = 100006 // ErrInvalidMessage - 400: Invalid message. ErrInvalidMessage = 100007 // ErrInternalServerError - 500: Internal server error. ErrInternalServerError = 100008 )
Base: 平台级非业务错误码 (100001~100999).
const ( // ErrEncodingFailed - 500: Encoding failed due to an error with the data. ErrEncodingFailed = 100201 // ErrDecodingFailed - 500: Decoding failed due to an error with the data. ErrDecodingFailed = 100202 // ErrInvalidJSON - 500: Data is not valid JSON. ErrInvalidJSON = 100203 // ErrEncodingJSON - 500: JSON data could not be encoded. ErrEncodingJSON = 100204 // ErrDecodingJSON - 500: JSON data could not be decoded. ErrDecodingJSON = 100205 // ErrInvalidYaml - 500: Data is not valid Yaml. ErrInvalidYaml = 100206 // ErrEncodingYaml - 500: Yaml data could not be encoded. ErrEncodingYaml = 100207 // ErrDecodingYaml - 500: Yaml data could not be decoded. ErrDecodingYaml = 100208 )
Base: 编码/解码错误 (100201~100299).
const ( // ErrModuleInitializationFailed - 500: Module initialization failed. ErrModuleInitializationFailed = 100301 // ErrModuleNotFound - 404: Module not found. ErrModuleNotFound = 100302 )
Base: 模块错误 (100301~100399).
const ( // ErrUserNotFound - 404: User not found. ErrUserNotFound = 101000 // ErrUserAlreadyExists - 400: User already exist. ErrUserAlreadyExists = 101001 // ErrUserBasicInfoInvalid - 400: User basic info is invalid. ErrUserBasicInfoInvalid = 101002 // ErrUserStatusInvalid - 400: User status is invalid. ErrUserStatusInvalid = 101003 // ErrUserInvalid - 400: User is invalid. ErrUserInvalid = 101004 // ErrUserBlocked - 403: User is blocked. ErrUserBlocked = 101005 // ErrUserInactive - 403: User is inactive. ErrUserInactive = 101006 )
Identity: 用户基础错误 (101000~101099).
const ( // ErrIdentityChildExists - 400: 儿童档案已存在 ErrIdentityChildExists = 101100 // ErrIdentityChildNotFound - 404: 儿童不存在 ErrIdentityChildNotFound = 101101 )
Identity: 儿童档案错误 (101100~101199).
const ( // ErrIdentityGuardianshipExists - 400: 监护关系已存在 ErrIdentityGuardianshipExists = 101200 // ErrIdentityGuardianshipNotFound - 404: 监护关系不存在 ErrIdentityGuardianshipNotFound = 101201 )
Identity: 监护关系错误 (101200~101299).
const (
// ErrDatabase - 500: Database error.
ErrDatabase = 100101
)
Base: 数据库错误 (100101~100199).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
This section is empty.