You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I always like to check my form fields to see if their values are convertible to needed types and if not then inform the user about invalid fields. form produces *errors.errorString and this is not useful when generating error responses for this purpose.
What about defining a new error type such as below to give more control over them
e.g.
typeError []Fieldfunc (eError) Error() string {
return"todo"
}
typeFieldstruct {
Namestring// tag name e.g. time from form:"time"Messagestring// original error message Type reflect.Type// point out the expected type so we can generate even more graceful error messages by checking this e.g. "time must be a UTC date"SliceIndexint// point out the index if an invalid Type placed in a slice except []byte
}
A dummy usage:
typePoststruct {
Time time.Time`form:"time"`
}
varpPosterr:=form.DecodeValues(&p, url.Values{"time", []string{"AnInvalidDate"}})
if (err.(form.Error))[0].Type==form.TimeType {
// so I can response a nice error message to user like:// HTTP 400// {"message": "Invalid Form Data", fields: {"time": "must be UTC formatted"}}
}
I'd like to implement this if you'll consider accepting the PR
The text was updated successfully, but these errors were encountered:
@ilgooz Sorry for the late response. I would not mind extending the error returned by form in the manner you propose, if you'd like to implement it. Feel free to open a PR and assign it to me.
I always like to check my form fields to see if their values are convertible to needed types and if not then inform the user about invalid fields. form produces *errors.errorString and this is not useful when generating error responses for this purpose.
What about defining a new error type such as below to give more control over them
e.g.
A dummy usage:
I'd like to implement this if you'll consider accepting the PR
The text was updated successfully, but these errors were encountered: