diff --git a/errs/error_code.go b/errs/error_code.go index 6a9035d..bdc05e6 100644 --- a/errs/error_code.go +++ b/errs/error_code.go @@ -24,3 +24,40 @@ func ThirdPartyErrorL(scope uint32, ec ErrorCode, return e } + +func DatabaseErrorWithScope(scope uint32, ec ErrorCode, s ...string) *ers.LibError { + return NewError(scope, code.DBError, ec.ToUint32(), strings.Join(s, " ")) +} + +func DatabaseErrorWithScopeL(scope uint32, + ec ErrorCode, + l logx.Logger, filed []logx.LogField, s ...string) *ers.LibError { + e := DatabaseErrorWithScope(scope, ec, s...) + l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) + + return e +} + +func ResourceNotFoundWithScope(scope uint32, ec ErrorCode, s ...string) *LibError { + return NewError(scope, code.ResourceNotFound, ec.ToUint32(), fmt.Sprintf("resource not found: %s", strings.Join(s, " "))) +} + +func ResourceNotFoundWithScopeL(scope uint32, ec ErrorCode, + l logx.Logger, filed []logx.LogField, s ...string) *LibError { + e := ResourceNotFoundWithScope(scope, ec, s...) + l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) + + return e +} + +func InvalidRangeWithScope(scope uint32, ec ErrorCode, s ...string) *LibError { + return NewError(scope, code.CatInput, ec.ToUint32(), fmt.Sprintf("invalid range: %s", strings.Join(s, " "))) +} + +func InvalidFormatWithScope(scope uint32, s ...string) *LibError { + return NewError(scope, code.CatInput, code.InvalidFormat, fmt.Sprintf("invalid range: %s", strings.Join(s, " "))) +} + +func ForbiddenWithScope(scope uint32, ec ErrorCode, s ...string) *LibError { + return NewError(scope, code.Forbidden, ec.ToUint32(), fmt.Sprintf("forbidden: %s", strings.Join(s, " "))) +}