mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-23 09:51:22 +08:00
Merge fd6ffcc01e0b834a8827a21a010383a793a6e6ef into 8763f33c65f7df8be5b9fe7504ab7fcf20abb41d
This commit is contained in:
commit
fcbefaaefc
@ -235,6 +235,11 @@ func (c *Context) AbortWithError(code int, err error) *Error {
|
|||||||
/********* ERROR MANAGEMENT *********/
|
/********* 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.
|
// 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.
|
// 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,
|
// A middleware can be used to collect all the errors and push them to a database together,
|
||||||
@ -242,7 +247,9 @@ func (c *Context) AbortWithError(code int, err error) *Error {
|
|||||||
// Error will panic if err is nil.
|
// Error will panic if err is nil.
|
||||||
func (c *Context) Error(err error) *Error {
|
func (c *Context) Error(err error) *Error {
|
||||||
if err == nil {
|
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
|
var parsedError *Error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user