The clear interaction for user (#1916)

Content-type is not be promise from RFC2616 7.2.1.
it may be need a clear describe info:)
pull/2080/head
workman-Lu 3 years ago committed by GitHub
parent c6f6caa887
commit d1550b366b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      transport/http/codec.go

@ -1,6 +1,7 @@
package http
import (
"fmt"
"io"
"net/http"
@ -40,7 +41,7 @@ type EncodeErrorFunc func(http.ResponseWriter, *http.Request, error)
func DefaultRequestDecoder(r *http.Request, v interface{}) error {
codec, ok := CodecForRequest(r, "Content-Type")
if !ok {
return errors.BadRequest("CODEC", r.Header.Get("Content-Type"))
return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", r.Header.Get("Content-Type")))
}
data, err := io.ReadAll(r.Body)
if err != nil {
@ -50,7 +51,7 @@ func DefaultRequestDecoder(r *http.Request, v interface{}) error {
return nil
}
if err = codec.Unmarshal(data, v); err != nil {
return errors.BadRequest("CODEC", err.Error())
return errors.BadRequest("CODEC", fmt.Sprintf("body unmarshal %s", err.Error()))
}
return nil
}

Loading…
Cancel
Save