mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
HttpJsonRequest user friendly message.
This commit is contained in:
parent
da71c9261d
commit
655d64105e
@ -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 {
|
||||||
|
if err == io.EOF {
|
||||||
|
HttpBadRequest(w, "No data provided.")
|
||||||
|
} else {
|
||||||
HttpBadRequest(w, err)
|
HttpBadRequest(w, err)
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user