Skip to content

Commit

Permalink
revert: work backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
balcieren committed Feb 12, 2022
1 parent 232c877 commit 0a961b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
29 changes: 6 additions & 23 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ type ErrorHandler = func(*Ctx, error) error

// Error represents an error that occurred while handling a request.
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
AnyMessage interface{} `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
}

// App denotes the Fiber application.
Expand Down Expand Up @@ -727,29 +726,13 @@ func (e *Error) Error() string {
}

// NewError creates a new Error instance with an optional message
func NewError(code int, message ...interface{}) *Error {
func NewError(code int, message ...string) *Error {
err := &Error{
Code: code,
Message: utils.StatusMessage(code),
AnyMessage: utils.StatusMessage(code),
Code: code,
Message: utils.StatusMessage(code),
}
if len(message) > 0 {
err.Message = utils.ToString(message[0])
err.AnyMessage = message[0]
}
return err
}

// NewErrors creates multiple new Error messages
func NewErrors(code int, messages ...interface{}) *Error {
err := &Error{
Code: code,
Message: utils.StatusMessage(code),
AnyMessage: utils.StatusMessage(code),
}
if len(messages) > 0 {
err.Message = utils.ToString(messages)
err.AnyMessage = messages
err.Message = message[0]
}
return err
}
Expand Down
8 changes: 0 additions & 8 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,6 @@ func Test_NewError(t *testing.T) {
utils.AssertEqual(t, "permission denied", err.Message)
}

func Test_NewErrors(t *testing.T) {
err := NewErrors(StatusBadRequest, "error 1", "error 2")
messages := err.AnyMessage.([]interface{})
utils.AssertEqual(t, StatusBadRequest, err.Code)
utils.AssertEqual(t, "error 1", fmt.Sprint(messages[0]))
utils.AssertEqual(t, "error 2", fmt.Sprint(messages[1]))
}

// go test -run Test_Test_Timeout
func Test_Test_Timeout(t *testing.T) {
app := New()
Expand Down

0 comments on commit 0a961b1

Please sign in to comment.