From 396c01bd756685c03b276dd6d8f1a574359009d0 Mon Sep 17 00:00:00 2001 From: soroush Date: Tue, 5 Sep 2017 11:00:51 +0430 Subject: [PATCH 1/2] Change validation status code This commit changes ShouldBind 400 error code to 422 because it makes more sense for validation errors --- context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index d7b6c61d..8bd39ec6 100644 --- a/context.go +++ b/context.go @@ -473,11 +473,11 @@ func (c *Context) BindQuery(obj interface{}) error { } // MustBindWith binds the passed struct pointer using the specified binding engine. -// It will abort the request with HTTP 400 if any error ocurrs. +// It will abort the request with HTTP 422(Unprocessable Entity) if any error ocurrs. // See the binding package. func (c *Context) MustBindWith(obj interface{}, b binding.Binding) (err error) { if err = c.ShouldBindWith(obj, b); err != nil { - c.AbortWithError(400, err).SetType(ErrorTypeBind) + c.AbortWithError(422, err).SetType(ErrorTypeBind) } return From 17cc6e95e68fb6e96607544562c27e7419fdf3ea Mon Sep 17 00:00:00 2001 From: soroush Date: Tue, 5 Sep 2017 11:30:47 +0430 Subject: [PATCH 2/2] Change assert to 422 --- context_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context_test.go b/context_test.go index 15569bf2..d7f50e74 100644 --- a/context_test.go +++ b/context_test.go @@ -1219,7 +1219,7 @@ func TestContextBadAutoBind(t *testing.T) { assert.Empty(t, obj.Bar) assert.Empty(t, obj.Foo) - assert.Equal(t, w.Code, 400) + assert.Equal(t, w.Code, 422) assert.True(t, c.IsAborted()) }