This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-09-14 01:09:51 +03:00
parent fd5a2a7c58
commit 7113165cb8
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7
3 changed files with 34 additions and 11 deletions

View File

@ -125,9 +125,14 @@ func (s *Struct) Acquire(ctx *context.Context) (reflect.Value, error) {
continue
}
s.Container.GetErrorHandler(ctx).HandleError(ctx, err)
if ctx.IsStopped() {
// return emptyValue, err
return ctrl, err
} // #1629
}
elem.FieldByIndex(b.Input.StructFieldIndex).Set(input)
}
}

View File

@ -713,15 +713,17 @@ 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().
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)
}