From b8798ec5f70a00f84f0ed64fab461a06b9d8919e Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Wed, 2 Jul 2014 02:32:44 +0200 Subject: [PATCH] Adds context.LastError() --- gin.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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********/ /************************************/