Merge fd6ffcc01e0b834a8827a21a010383a793a6e6ef into e88fc8927a52b74f55bec0351604a56ac0aa1c51

This commit is contained in:
fthandsome 2025-11-21 10:23:44 +01:00 committed by GitHub
commit a2ac5dbc7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -251,6 +251,11 @@ func (c *Context) AbortWithError(code int, err error) *Error {
/********* ERROR MANAGEMENT *********/
/************************************/
// Avoid panic case
var emptyError = &Error{
Err: fmt.Errorf("err is nil"),
Type: ErrorTypePrivate,
}
// Error attaches an error to the current context. The error is pushed to a list of errors.
// It's a good idea to call Error for each error that occurred during the resolution of a request.
// A middleware can be used to collect all the errors and push them to a database together,
@ -258,7 +263,9 @@ func (c *Context) AbortWithError(code int, err error) *Error {
// Error will panic if err is nil.
func (c *Context) Error(err error) *Error {
if err == nil {
panic("err is nil")
// Avoid panic case, and do not push it into c.Errors
return emptyError
//panic("err is nil")
}
var parsedError *Error