Skip to content

Commit

Permalink
set Status when newing codeint.Error
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Apr 21, 2024
1 parent 5449dcf commit fefeb89
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions result/codeint/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Error struct {
}

// NewError returns a new Error with the code.
func NewError(code int) Error { return Error{Code: code} }
func NewError(code int) Error { return Error{Code: code}.WithStatus(code) }

// IsZero reports whether e is ZERO.
func (e Error) IsZero() bool {
Expand Down Expand Up @@ -98,7 +98,11 @@ func (e Error) WithMessage(msg string, args ...interface{}) Error {

// WithStatus returns a new Error with the status.
func (e Error) WithStatus(status int) Error {
e.Status = status
if status < 600 {
e.Status = status
} else {
e.Status = 500
}
return e
}

Expand Down

0 comments on commit fefeb89

Please sign in to comment.