code

package
v5.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package code defines shared error codes used across the iam services.

错误码按照"通用能力 + 业务模块"进行分层管理,方便在系统中快速定位并统一处理。 每个文件代表一个模块或域的错误码定义:

  • base.go :平台级非业务错误码(如绑定、校验、数据库、编码等),范围:100001~100999
  • identity.go :基础用户及身份档案/监护等领域错误码,范围:101000~101999
  • authn.go :认证(Authentication)相关所有错误码(包含 JWKS),范围:102000~102999
  • authz.go :授权(Authorization)相关所有错误码,范围:103000~103999
  • 其他错误码 :预留范围:104000~104999

约定:

  1. 错误码统一通过 pkg/errors.WithCode / WrapC 产出,确保能够被统一解析。
  2. 不同模块的错误码区间互不重叠,便于排查(详见各文件中的常量定义)。
  3. 错误码命名遵循 Err + 模块 + 问题描述 的形式,例如 ErrUserNotFound。

使用示例:

return errors.WithCode(code.ErrUserNotFound, "user(%s) not found", userID)

Index

Constants

View Source
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).

View Source
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).

View Source
const (
	ErrLoginIdentityExists     = 102200
	ErrExternalIdentityExists  = 102201
	ErrLoginIdentityNotFound   = 102202
	ErrGlobalIdentifierExists  = 102203
	ErrInvalidGlobalIdentifier = 102204
	ErrLoginIdentityDisabled   = 102205
)

Authn: 登录身份相关错误码 (102200~102299).

View Source
const (
	ErrCredentialExists    = 102300
	ErrCredentialNotFound  = 102301
	ErrCredentialLocked    = 102302
	ErrCredentialExpired   = 102303
	ErrCredentialDisabled  = 102304
	ErrInvalidCredential   = 102305
	ErrCredentialNotUsable = 102306
)

Authn: 凭据相关错误码 (102300~102399).

View Source
const (
	ErrAuthenticationFailed     = 102400
	ErrOTPInvalid               = 102401
	ErrStateMismatch            = 102402
	ErrIDPExchangeFailed        = 102403
	ErrNoBinding                = 102404
	ErrOTPSendTooFrequent       = 102405
	ErrTokenRevokeFailed        = 102406
	ErrUnsupportedAuthMethod    = 102407
	ErrPayloadInvalid           = 102408
	ErrProofBuildFailed         = 102409
	ErrRefreshTokenNotFound     = 102410
	ErrRefreshTokenExpired      = 102411
	ErrSessionInactive          = 102412
	ErrReauthenticationRequired = 102413
)

Authn: 认证流程相关错误码 (102400~102499).

View Source
const (
	// ErrUnauthorized - 403: Authorization failed.
	ErrUnauthorized = 103000

	// ErrPermissionDenied - 403: Permission denied.
	ErrPermissionDenied = 103001

	// ErrAuthorizationPolicyUnavailable - 503: policy freshness cannot be established.
	ErrAuthorizationPolicyUnavailable = 103002
)

Authz: 基础权限错误 (103000~103099).

View Source
const (
	// ErrRoleNotFound - 404: Role not found.
	ErrRoleNotFound = 103100

	// ErrRoleAlreadyExists - 409: Role already exists.
	ErrRoleAlreadyExists = 103101

	// ErrRoleInheritanceAlreadyExists - 409: Role inheritance already exists.
	ErrRoleInheritanceAlreadyExists = 103102

	// ErrRoleInUse - 409: Role still has active authorization facts.
	ErrRoleInUse = 103103
)

Authz: 角色相关错误 (103100~103199).

View Source
const (
	// ErrResourceNotFound - 404: Resource not found.
	ErrResourceNotFound = 103200

	// ErrResourceAlreadyExists - 409: Resource already exists.
	ErrResourceAlreadyExists = 103201

	// ErrInvalidAction - 400: Invalid action for resource.
	ErrInvalidAction = 103202

	// ErrResourceInUse - 409: Resource still has active permission grants.
	ErrResourceInUse = 103203
)

Authz: 资源相关错误 (103200~103299).

View Source
const (
	// ErrAssignmentNotFound - 404: Assignment not found.
	ErrAssignmentNotFound = 103300

	// ErrAssignmentAlreadyExists - 409: Assignment already exists.
	ErrAssignmentAlreadyExists = 103301
)

Authz: 赋权相关错误 (103300~103399).

View Source
const (
	// ErrPolicyVersionNotFound - 404: Policy version not found.
	ErrPolicyVersionNotFound = 103400
	// ErrPolicyVersionAlreadyExists - 409: Policy version already exists.
	ErrPolicyVersionAlreadyExists = 103401

	// ErrPermissionGrantAlreadyExists - 409: Permission grant already exists.
	ErrPermissionGrantAlreadyExists = 103402
)

Authz: 策略相关错误 (103400~103499).

View Source
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).

View Source
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).

View Source
const (
	// ErrModuleInitializationFailed - 500: Module initialization failed.
	ErrModuleInitializationFailed = 100301

	// ErrModuleNotFound - 404: Module not found.
	ErrModuleNotFound = 100302

	// ErrRateLimited - 429: Too many requests.
	ErrRateLimited = 100303
)

Base: 模块错误 (100301~100399).

View Source
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).

View Source
const (
	// ErrIdentityProfileExists - 400: 档案已存在
	ErrIdentityProfileExists = 101100

	// ErrIdentityProfileNotFound - 404: 档案不存在
	ErrIdentityProfileNotFound = 101101
)

Identity: 档案错误 (101100~101199).

View Source
const (
	// ErrIdentityProfileLinkExists - 400: 档案关系已存在
	ErrIdentityProfileLinkExists = 101200

	// ErrIdentityProfileLinkNotFound - 404: 档案关系不存在
	ErrIdentityProfileLinkNotFound = 101201
)

Identity: 档案关系错误 (101200~101299).

View Source
const (
	// ErrWechatAppNotFound - 404: Wechat app not found.
	ErrWechatAppNotFound = 104000

	// ErrWechatAppAlreadyExists - 409: Wechat app already exists.
	ErrWechatAppAlreadyExists = 104001

	// ErrWechatAppTypeInvalid - 400: Wechat app type is invalid.
	ErrWechatAppTypeInvalid = 104002

	// ErrWechatAppStatusInvalid - 400: Wechat app status is invalid.
	ErrWechatAppStatusInvalid = 104003

	// ErrWechatAppTypeMismatch - 400: Wechat app type does not match the expected type for this flow.
	ErrWechatAppTypeMismatch = 104004
)

IDP: 身份提供商相关错误码 (104000~104999).

View Source
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL