Giter Club home page Giter Club logo

Comments (8)

mholt avatar mholt commented on August 26, 2024

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.

mhemmings avatar mhemmings commented on August 26, 2024

👍 +1 for 400: Bad Request :)

from binding.

mholt avatar mholt commented on August 26, 2024

sigh I got the commit message wrong, but the code is right. 81bd158

from binding.

jchannon avatar jchannon commented on August 26, 2024

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.

mholt avatar mholt commented on August 26, 2024

Sure, we can see what people think.

from binding.

bhcleek avatar bhcleek commented on August 26, 2024

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.

jchannon avatar jchannon commented on August 26, 2024

Do you mean write my own Handle method not pass my own ResponseWriter?

from binding.

bhcleek avatar bhcleek commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.