Commit
* fix new errors * fix tests * removed new errors tests * changed error message type * fixed NewError test * added NewErrors function * added Test_NewErrors * added comment line * refactor: Sprintf changed with Sprint
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,8 +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"` | ||
Code int `json:"code"` | ||
Message interface{} `json:"message"` | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
efectn
Member
|
||
} | ||
|
||
// App denotes the Fiber application. | ||
|
@@ -715,43 +715,31 @@ func (app *App) Route(prefix string, fn func(router Router), name ...string) Rou | |
|
||
// Error makes it compatible with the `error` interface. | ||
func (e *Error) Error() string { | ||
return e.Message | ||
return fmt.Sprint(e.Message) | ||
} | ||
|
||
// NewError creates a new Error instance with an optional message | ||
func NewError(code int, message ...string) *Error { | ||
func NewError(code int, message ...interface{}) *Error { | ||
e := &Error{ | ||
Code: code, | ||
Code: code, | ||
Message: utils.StatusMessage(code), | ||
} | ||
if len(message) > 0 { | ||
e.Message = message[0] | ||
} else { | ||
e.Message = utils.StatusMessage(code) | ||
} | ||
return e | ||
} | ||
|
||
// NewErrors creates multiple new Errors instance with some message | ||
func NewErrors(code int, messages ...string) []*Error { | ||
var errors []*Error | ||
// NewErrors creates multiple new Error messages | ||
func NewErrors(code int, messages ...interface{}) *Error { | ||
e := &Error{ | ||
Code: code, | ||
Message: utils.StatusMessage(code), | ||
} | ||
if len(messages) > 0 { | ||
for _, message := range messages { | ||
e := &Error{ | ||
Code: code, | ||
} | ||
e.Message = message | ||
errors = append(errors, e) | ||
} | ||
} else { | ||
// Use default messages | ||
e := &Error{ | ||
Code: code, | ||
} | ||
e.Message = utils.StatusMessage(code) | ||
errors = append(errors, e) | ||
e.Message = messages | ||
} | ||
|
||
return errors | ||
return e | ||
} | ||
|
||
// Listener can be used to pass a custom listener. | ||
|
1 comment
on commit 7cf1886
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review my comment and consider reverting the change mentioned. As it wasn't necessary and only caused backwards incompatibility.
This violates symantic versioning and has broken my project. MINOR version modifications are almost always to be done in a backwards-compatible manner. https://semver.org/
Treating this field as a string or using assignment with the concrete type "string" now causes an error. Please keep this in mind going forward so that others don't have to constantly downgrade their modules because of non-semantic updates.