-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Read* like ReadQuery ignores "required" tags and don't kick out an error #1727
Comments
Okay i found out that if you don't provide any querystrings you don't get a error. But if you only provide only one you get the errors. I think this needs to be fixed. type MyQuery struct {
Session string `url:"s,required"`
Page string `url:"p,required"`
SubPage string `url:"sp"`
Action string `url:"a"`
}
|
@Dexus this is working on me. And your example also works:(both are missing): Maybe you have the |
Try it without a querystring attached and then there is no error
Von meinem iPhone gesendet
… Am 14.02.2021 um 12:20 schrieb Gerasimos (Makis) Maropoulos ***@***.***>:
To Reproduce
https://github.com/kataras/iris/blob/master/_examples/request-body/read-query/main.go < don't send a query with name in it -> no error
@Dexus this is working on me.
Maybe you have the iris.IsErrPath(err) ignored?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Of course there is no error without query string. You have to first check if the URL Query is empty. This is intentional: func (ctx *Context) ReadQuery(ptr interface{}) error {
values := ctx.getQuery()
if len(values) == 0 {
return nil // HERE
}
// ... But if you want we can respect the func (ctx *Context) ReadForm(formObject interface{}) error {
values := ctx.FormValues()
if len(values) == 0 {
if ctx.app.ConfigurationReadOnly().GetFireEmptyFormError() {
return ErrEmptyForm
}
return nil
}
// .... |
That would be a greate idea! |
OK I am on it! Can you also please reply to you other issues labeld as "BUG" too? (e.g. #1723) thanks! |
OK It's done, upgrade on latest |
@kataras did update the other issue |
it would be cool if we can alias schema.MultiError to catch the error of this type. Because schema will collect the errors into this type. |
@Dexus Hmm what do you mean? If the data are empty, there is no other "error" that can happen (so MultiError has no reason to contain that error), decoder won't be fired at all to check the fields (the source is empty). Can you give me a usecase example so I provide a better option for you? |
Hi @kataras if I have only one required field filled, i get an error of MultiError ( var (
errMultiError = &schema.MultiError{}
errEmptyField = &schema.EmptyFieldError{}
)
// CheckErr ...
func CheckErr(ctx iris.Context, err error) bool {
if err != nil && err == iris.ErrEmptyForm {
ctx.StopWithError(iris.StatusBadRequest, errors.New("error (e#10001)"))
ctx.StopExecution()
return true
} else if err != nil && iris.IsErrPath(err) {
ctx.StopWithError(iris.StatusBadRequest, errors.New("error (e#10002)"))
ctx.StopExecution()
return true
} else if err != nil && errors.Is(err, iris.ErrEmptyFormField) {
ctx.StopWithError(iris.StatusBadRequest, errors.New("error (e#10005)"))
ctx.StopExecution()
return true
} else if err != nil && errors.As(err, errMultiError) {
ctx.StopWithError(iris.StatusBadRequest, errors.New("error (e#10003)"))
ctx.StopExecution()
return true
} else if err != nil && errors.As(err, errEmptyField) {
ctx.StopWithError(iris.StatusBadRequest, errors.New("error (e#10004)"))
ctx.StopExecution()
return true
} else if err != nil {
ctx.StopWithError(iris.StatusInternalServerError, err)
ctx.StopExecution()
return true
}
return false
} |
Describe the bug
Schema supportet Reader dont respect "required" tag
To Reproduce
https://github.com/kataras/iris/blob/master/_examples/request-body/read-query/main.go < don't send a query with name in it -> no error
Expected behavior
Requests without the required fileds, should return an error.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
iris.Version
Additional context
Maybe the https://github.com/iris-contrib/schema need an update and/or fixes?
The text was updated successfully, but these errors were encountered: