HttpJsonRequest user friendly message.
This commit is contained in:
parent
da71c9261d
commit
655d64105e
1 changed files with 7 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -14,7 +15,12 @@ type ErrResponse struct {
|
||||||
|
|
||||||
func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res interface{}) bool {
|
func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res interface{}) bool {
|
||||||
if err := json.NewDecoder(r.Body).Decode(res); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(res); err != nil {
|
||||||
HttpBadRequest(w, err)
|
if err == io.EOF {
|
||||||
|
HttpBadRequest(w, "No data provided.")
|
||||||
|
} else {
|
||||||
|
HttpBadRequest(w, err)
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue