HttpJsonRequest user friendly message.

This commit is contained in:
Miroslav Šedivý 2020-12-27 21:07:09 +01:00
parent da71c9261d
commit 655d64105e

View File

@ -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
} }