Skip to content

Commit

Permalink
Add NewOrElse
Browse files Browse the repository at this point in the history
  • Loading branch information
PumpkinSeed committed Apr 12, 2023
1 parent 5ae468c commit 3f11809
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions weird/weird.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func New(msg string, err error, statusCode int) error {
}
}

func NewOrElse(msg string, err error, statusCode int) error {
if _, ok := err.(Error); ok {
return err
}
return New(msg, err, statusCode)
}

// Error satisfy the error interface and format the error
func (e Error) Error() string {
if e.InnerError != nil {
Expand Down

0 comments on commit 3f11809

Please sign in to comment.