guard/internal/domain/errors.go

66 lines
2.1 KiB
Go
Raw Normal View History

2024-08-08 03:02:13 +00:00
package domain
import (
2024-08-08 08:10:38 +00:00
mts "ark-permission/internal/lib/metric"
2024-08-08 03:02:13 +00:00
ers "code.30cm.net/wanderland/library-go/errors"
"code.30cm.net/wanderland/library-go/errors/code"
)
// 12 represents Scope
2024-08-08 08:10:38 +00:00
// 100 represents Category
// 9 represents Detail error code
// full code 12009 只會有 系統以及錯誤碼category 是給系統判定用的
// 目前 Scope 以及分類要系統共用,係向的錯誤各自服務實作就好
const (
TokenUnexpectedSigningErrorCode = iota + 1
TokenValidateErrorCode
TokenClaimErrorCode
)
2024-08-08 03:02:13 +00:00
const (
2024-08-08 08:10:38 +00:00
RedisDelErrorCode = iota + 20
RedisPipLineErrorCode
2024-08-10 01:52:23 +00:00
RedisErrorCode
2024-08-08 03:02:13 +00:00
)
2024-08-08 08:10:38 +00:00
// TokenUnexpectedSigningErr 30001 Token 簽名錯誤
2024-08-08 03:02:13 +00:00
func TokenUnexpectedSigningErr(msg string) *ers.Err {
2024-08-08 08:10:38 +00:00
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")
2024-08-10 01:52:23 +00:00
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-08 03:02:13 +00:00
}