mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
fix #1629
This commit is contained in:
parent
fd5a2a7c58
commit
7113165cb8
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user