2024-08-12 14:20:13 +00:00
|
|
|
|
package domain
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
mts "ark-permission/internal/lib/metric"
|
|
|
|
|
|
|
|
|
|
ers "code.30cm.net/wanderland/library-go/errors"
|
|
|
|
|
"code.30cm.net/wanderland/library-go/errors/code"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 12 represents Scope
|
|
|
|
|
// 100 represents Category
|
|
|
|
|
// 9 represents Detail error code
|
|
|
|
|
// full code 12009 只會有 系統以及錯誤碼,category 是給系統判定用的
|
|
|
|
|
// 目前 Scope 以及分類要系統共用,係向的錯誤各自服務實作就好
|
|
|
|
|
|
2024-08-18 14:09:51 +00:00
|
|
|
|
// token error 方面
|
2024-08-12 14:20:13 +00:00
|
|
|
|
const (
|
|
|
|
|
TokenUnexpectedSigningErrorCode = iota + 1
|
|
|
|
|
TokenValidateErrorCode
|
|
|
|
|
TokenClaimErrorCode
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
RedisDelErrorCode = iota + 20
|
|
|
|
|
RedisPipLineErrorCode
|
|
|
|
|
RedisErrorCode
|
|
|
|
|
)
|
|
|
|
|
|
2024-08-18 14:09:51 +00:00
|
|
|
|
const (
|
|
|
|
|
PermissionNotFoundCode = iota + 30
|
|
|
|
|
PermissionGetDataErrorCode
|
|
|
|
|
)
|
|
|
|
|
|
2024-08-12 14:20:13 +00:00
|
|
|
|
// TokenUnexpectedSigningErr 30001 Token 簽名錯誤
|
|
|
|
|
func TokenUnexpectedSigningErr(msg string) *ers.Err {
|
|
|
|
|
mts.AppErrorMetrics.AddFailure("token", "token_unexpected_sign")
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.CatInput, TokenUnexpectedSigningErrorCode, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TokenTokenValidateErr 30002 Token 驗證錯誤
|
|
|
|
|
func TokenTokenValidateErr(msg string) *ers.Err {
|
|
|
|
|
mts.AppErrorMetrics.AddFailure("token", "token_validate_ilegal")
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.CatInput, TokenValidateErrorCode, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TokenClaimError 30003 Token 驗證錯誤
|
|
|
|
|
func TokenClaimError(msg string) *ers.Err {
|
|
|
|
|
mts.AppErrorMetrics.AddFailure("token", "token_claim_error")
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.CatInput, TokenClaimErrorCode, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedisDelError 30020 Redis 刪除錯誤
|
|
|
|
|
func RedisDelError(msg string) *ers.Err {
|
|
|
|
|
// 看需要建立哪些 Metrics
|
|
|
|
|
mts.AppErrorMetrics.AddFailure("redis", "del_error")
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.CatDB, RedisDelErrorCode, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedisPipLineError 30021 Redis PipLine 錯誤
|
|
|
|
|
func RedisPipLineError(msg string) *ers.Err {
|
|
|
|
|
// 看需要建立哪些 Metrics
|
|
|
|
|
mts.AppErrorMetrics.AddFailure("redis", "pip_line_error")
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.CatInput, RedisPipLineErrorCode, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedisError 30022 Redis 錯誤
|
|
|
|
|
func RedisError(msg string) *ers.Err {
|
|
|
|
|
// 看需要建立哪些 Metrics
|
|
|
|
|
mts.AppErrorMetrics.AddFailure("redis", "error")
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.CatInput, RedisErrorCode, msg)
|
|
|
|
|
}
|
2024-08-18 14:09:51 +00:00
|
|
|
|
|
|
|
|
|
// PermissionNotFoundError 30030 權限錯誤
|
|
|
|
|
func PermissionNotFoundError(msg string) *ers.Err {
|
|
|
|
|
// 看需要建立哪些 Metrics
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.Forbidden, PermissionNotFoundCode, msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PermissionGetDataError 30031 解析權限時錯誤
|
|
|
|
|
func PermissionGetDataError(msg string) *ers.Err {
|
|
|
|
|
// 看需要建立哪些 Metrics
|
|
|
|
|
return ers.NewErr(code.CloudEPPermission, code.InvalidFormat, PermissionGetDataErrorCode, msg)
|
|
|
|
|
}
|