From d1d5747616ee4687c86b23c7d36b3009dc405dda Mon Sep 17 00:00:00 2001 From: sidbusy Date: Wed, 13 Jul 2016 13:54:40 +0800 Subject: [PATCH] allow to custom the error handle --- context.go | 6 +----- context_test.go | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/context.go b/context.go index 5d3b6a4e38..33721587b8 100644 --- a/context.go +++ b/context.go @@ -296,11 +296,7 @@ func (c *Context) BindJSON(obj interface{}) error { // BindWith binds the passed struct pointer using the specified binding engine. // See the binding package. func (c *Context) BindWith(obj interface{}, b binding.Binding) error { - if err := b.Bind(c.Request, obj); err != nil { - c.AbortWithError(400, err).SetType(ErrorTypeBind) - return err - } - return nil + return b.Bind(c.Request, obj) } // ClientIP implements a best effort algorithm to return the real client IP, it parses diff --git a/context_test.go b/context_test.go index 97d4957c6d..7bc1ccc173 100644 --- a/context_test.go +++ b/context_test.go @@ -671,7 +671,7 @@ func TestContextBindWithJSON(t *testing.T) { } func TestContextBadAutoBind(t *testing.T) { - c, w, _ := CreateTestContext() + c, _, _ := CreateTestContext() c.Request, _ = http.NewRequest("POST", "http://example.com", bytes.NewBufferString("\"foo\":\"bar\", \"bar\":\"foo\"}")) c.Request.Header.Add("Content-Type", MIMEJSON) var obj struct { @@ -679,14 +679,9 @@ func TestContextBadAutoBind(t *testing.T) { Bar string `json:"bar"` } - assert.False(t, c.IsAborted()) assert.Error(t, c.Bind(&obj)) - c.Writer.WriteHeaderNow() - assert.Empty(t, obj.Bar) assert.Empty(t, obj.Foo) - assert.Equal(t, w.Code, 400) - assert.True(t, c.IsAborted()) } func TestContextGolangContext(t *testing.T) {