Skip to content

Commit

Permalink
added Replace method for errors.Error interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dobyte committed Nov 29, 2022
1 parent 6997dab commit bbfa376
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions errors/error.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ type Error interface {
Cause() error
// Stack 返回堆栈
Stack() *stack.Stack
// Replace 替换文本
Replace(text string, condition ...code.Code) error
}

// NewError 新建一个错误
@@ -185,6 +187,15 @@ func (e *defaultError) Unwrap() error {
return e.err
}

// Replace 替换文本
func (e *defaultError) Replace(text string, condition ...code.Code) error {
if len(condition) == 0 || condition[0] == e.code {
e.text = text
}

return e
}

// String 格式化错误信息
func (e *defaultError) String() string {
return fmt.Sprintf("%+v", e)

0 comments on commit bbfa376

Please sign in to comment.