mirror of
https://github.com/kataras/iris.git
synced 2025-03-11 17:24:14 +01:00
fix #1629
This commit is contained in:
parent
fd5a2a7c58
commit
7113165cb8
|
@ -125,9 +125,14 @@ func (s *Struct) Acquire(ctx *context.Context) (reflect.Value, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Container.GetErrorHandler(ctx).HandleError(ctx, err)
|
||||||
|
|
||||||
|
if ctx.IsStopped() {
|
||||||
// return emptyValue, err
|
// return emptyValue, err
|
||||||
return ctrl, err
|
return ctrl, err
|
||||||
|
} // #1629
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.FieldByIndex(b.Input.StructFieldIndex).Set(input)
|
elem.FieldByIndex(b.Input.StructFieldIndex).Set(input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -713,14 +713,16 @@ func TestErrorHandlerContinue(t *testing.T) {
|
||||||
app := iris.New()
|
app := iris.New()
|
||||||
m := New(app)
|
m := New(app)
|
||||||
m.Handle(new(testControllerErrorHandlerContinue))
|
m.Handle(new(testControllerErrorHandlerContinue))
|
||||||
|
m.Handle(new(testControllerFieldErrorHandlerContinue))
|
||||||
e := httptest.New(t, app)
|
e := httptest.New(t, app)
|
||||||
|
|
||||||
e.POST("/test").WithMultipart().
|
for _, path := range []string{"/test", "/test/field"} {
|
||||||
|
e.POST(path).WithMultipart().
|
||||||
WithFormField("username", "makis").
|
WithFormField("username", "makis").
|
||||||
WithFormField("age", "27").
|
WithFormField("age", "27").
|
||||||
WithFormField("unknown", "continue").
|
WithFormField("unknown", "continue").
|
||||||
Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n")
|
Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type testControllerErrorHandlerContinue struct{}
|
type testControllerErrorHandlerContinue struct{}
|
||||||
|
@ -741,3 +743,19 @@ func (c *testControllerErrorHandlerContinue) HandleError(ctx iris.Context, err e
|
||||||
func (c *testControllerErrorHandlerContinue) PostTest(form registerForm) string {
|
func (c *testControllerErrorHandlerContinue) PostTest(form registerForm) string {
|
||||||
return fmt.Sprintf("%s is %d years old\n", form.Username, form.Age)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user