소스 검색

Adds context.LastError()

Manu Mtz-Almeida 11 년 전
부모
커밋
b8798ec5f7
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      gin.go

+ 10 - 0
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********/
 /************************************/