diff --git a/gin.go b/gin.go index 19a1ffa3..a74bcd8a 100644 --- a/gin.go +++ b/gin.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "encoding/xml" + "errors" "fmt" "github.com/julienschmidt/httprouter" "html/template" @@ -258,6 +259,15 @@ func (c *Context) Error(err error, meta interface{}) { }) } +func (c *Context) LastError() error { + s := len(c.Errors) + if s > 0 { + return errors.New(c.Errors[s-1].Err) + } else { + return nil + } +} + /************************************/ /******** METADATA MANAGEMENT********/ /************************************/