diff --git a/configuration.go b/configuration.go index 8b3e93d9..eae01ea8 100644 --- a/configuration.go +++ b/configuration.go @@ -805,9 +805,9 @@ type Configuration struct { // // Defaults to an empty slice but an example usage is: // RemoteAddrHeaders { - // "X-Real-Ip", - // "X-Forwarded-For", - // "CF-Connecting-IP", + // "X-Real-Ip", + // "X-Forwarded-For", + // "CF-Connecting-IP", // } // // Look `context.RemoteAddr()` for more. diff --git a/hero/struct.go b/hero/struct.go index 09f4d572..2a9d2af0 100644 --- a/hero/struct.go +++ b/hero/struct.go @@ -125,9 +125,14 @@ func (s *Struct) Acquire(ctx *context.Context) (reflect.Value, error) { continue } - // return emptyValue, err - return ctrl, err + s.Container.GetErrorHandler(ctx).HandleError(ctx, err) + + if ctx.IsStopped() { + // return emptyValue, err + return ctrl, err + } // #1629 } + elem.FieldByIndex(b.Input.StructFieldIndex).Set(input) } } diff --git a/mvc/controller_test.go b/mvc/controller_test.go index 0436ac5e..05355148 100644 --- a/mvc/controller_test.go +++ b/mvc/controller_test.go @@ -713,14 +713,16 @@ func TestErrorHandlerContinue(t *testing.T) { app := iris.New() m := New(app) m.Handle(new(testControllerErrorHandlerContinue)) - + m.Handle(new(testControllerFieldErrorHandlerContinue)) e := httptest.New(t, app) - e.POST("/test").WithMultipart(). - WithFormField("username", "makis"). - WithFormField("age", "27"). - WithFormField("unknown", "continue"). - Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n") + for _, path := range []string{"/test", "/test/field"} { + e.POST(path).WithMultipart(). + WithFormField("username", "makis"). + WithFormField("age", "27"). + WithFormField("unknown", "continue"). + Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n") + } } type testControllerErrorHandlerContinue struct{} @@ -741,3 +743,19 @@ func (c *testControllerErrorHandlerContinue) HandleError(ctx iris.Context, err e func (c *testControllerErrorHandlerContinue) PostTest(form registerForm) string { return fmt.Sprintf("%s is %d years old\n", form.Username, form.Age) } + +type testControllerFieldErrorHandlerContinue struct { + Form *registerForm +} + +func (c *testControllerFieldErrorHandlerContinue) HandleError(ctx iris.Context, err error) { + if iris.IsErrPath(err) { + return // continue. + } + + ctx.StopWithError(iris.StatusBadRequest, err) +} + +func (c *testControllerFieldErrorHandlerContinue) PostTestField() string { + return fmt.Sprintf("%s is %d years old\n", c.Form.Username, c.Form.Age) +}