mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
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:)
This commit is contained in:
parent
c6f6caa887
commit
d1550b366b
@ -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…
x
Reference in New Issue
Block a user