From 493233a52f3293c07b26f8afdf3484c656adf86d Mon Sep 17 00:00:00 2001 From: "daniel.w" Date: Fri, 15 Nov 2024 15:25:21 +0800 Subject: [PATCH] add error code --- errs/code/scope.go | 1 + errs/error_code.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/errs/code/scope.go b/errs/code/scope.go index 51263f1..519a922 100644 --- a/errs/code/scope.go +++ b/errs/code/scope.go @@ -10,4 +10,5 @@ const ( CloudEPTweeting CloudEPOrder CloudEPFileStorage + CloudEPProduct ) diff --git a/errs/error_code.go b/errs/error_code.go index c3603a5..d5e9eea 100644 --- a/errs/error_code.go +++ b/errs/error_code.go @@ -54,10 +54,34 @@ 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 InvalidRangeWithScopeL(scope uint32, ec ErrorCode, + l logx.Logger, filed []logx.LogField, s ...string) *LibError { + e := InvalidRangeWithScope(scope, ec, s...) + l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) + + return e +} + func InvalidFormatWithScope(scope uint32, s ...string) *LibError { return NewError(scope, code.CatInput, code.InvalidFormat, fmt.Sprintf("invalid range: %s", strings.Join(s, " "))) } +func InvalidFormatWithScopeL(scope uint32, + l logx.Logger, filed []logx.LogField, s ...string) *LibError { + e := InvalidFormatWithScope(scope, s...) + l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) + + return e +} + func ForbiddenWithScope(scope uint32, ec ErrorCode, s ...string) *LibError { return NewError(scope, code.Forbidden, ec.ToUint32(), fmt.Sprintf("forbidden: %s", strings.Join(s, " "))) } + +func ForbiddenWithScopeL(scope uint32, ec ErrorCode, + l logx.Logger, filed []logx.LogField, s ...string) *LibError { + e := ForbiddenWithScope(scope, ec, s...) + l.WithCallerSkip(1).WithFields(filed...).Error(e.Error()) + + return e +}