Comments (8)
Yeah, you're right, 422 is kind of weird. And I think it does mean something slightly different than what we think of as a "Bad Request" - and seeing as this is a general package, the more common error code should be returned.
I'll make this change eventually. Swamped with school right now, but will get around to it.
from binding.
👍 +1 for 400: Bad Request :)
from binding.
sigh I got the commit message wrong, but the code is right. 81bd158
from binding.
hi, I always use 422, is there a way to define the status code you would like? Happy to do a PR that adds func (e Errors) Handle(response http.ResponseWriter, statusCode int) bool {
from binding.
Sure, we can see what people think.
from binding.
I'd rather not do this. If you want to control the status code and error message, simply pass in an http.ResponseWriter implementation that does writes the status code you want.
from binding.
Do you mean write my own Handle method not pass my own ResponseWriter?
from binding.
No, I mean pass your own http.ResponseWriter to Errors.Handle
; maybe it looks something like this:
type BindingErrorWriter struct {
http.ResponseWriter
code int
}
func (w *BindingErrorWriter) WriteHeader(code int) {
if code > 0 {
return
}
if code == 422 {
code = 400
}
w.code = code
return w.ResponseWriter.WriteHeader(code)
}
func (w *BindingErrorWriter) Write(p []byte) (int, error) {
if w.code == 0 {
w.WriteHeader(200)
}
return w.ResponseWriter.Write(p)
}
from binding.
Related Issues (20)
- Expose *Binder interface for more byte oriented payloads HOT 2
- Feature request: Content-Type constraints HOT 1
- Re-thinking the binding package HOT 7
- Handling JSON arrays HOT 4
- template errors HOT 1
- Ability to control the HTTP error codes HOT 1
- autobindings to automatically create FieldMap functions for your structs HOT 1
- binding.Field.Required = true, ignored for struct fields. HOT 4
- JSON file as opposed to HTTPRequest? HOT 1
- Why not use govalidator internally? HOT 1
- Customise error message HOT 7
- Required error changed HOT 1
- Uploading file and json HOT 3
- Should FieldSpec.Binder have higher precedence than Binder.Bind?
- Errors object passed to Validate does not contain errors accumulated during Binding
- Automatic decoding of string HOT 1
- Best practice for operating on slices of data and keeping context HOT 4
- Binding Custom Types by Specifying Binder Func Does Not Work HOT 1
- [bug] error http: multipart handled by ParseMultipartForm if parse form before call binding.Bind HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binding.