added json serialization error handling

This commit is contained in:
Matthias Hannig 2017-07-10 14:02:41 +01:00
parent 06cf48f7e7
commit 5fda0be5f0
2 changed files with 10 additions and 1 deletions

View File

@ -1 +1 @@
2.2.4
2.2.5

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"net/http"
"log"
"strings"
"time"
@ -54,6 +55,14 @@ func endpoint(wrapped apiEndpoint) httprouter.Handle {
// Encode json
payload, err := json.Marshal(result)
if err != nil {
msg := "Could not encode result as json"
http.Error(res, msg, http.StatusInternalServerError)
log.Println(err)
log.Println("This is most likely due to an older version of go.")
log.Println("Consider upgrading to golang > 1.8")
return
}
// Set response header
res.Header().Set("Content-Type", "application/json")