diff --git a/exp/lighthorizon/actions/main.go b/exp/lighthorizon/actions/main.go index f7d784e503..28f6a6f517 100644 --- a/exp/lighthorizon/actions/main.go +++ b/exp/lighthorizon/actions/main.go @@ -3,7 +3,6 @@ package actions import ( "embed" "encoding/json" - "fmt" "net/http" "net/url" "strconv" @@ -55,22 +54,37 @@ type pagination struct { } func sendPageResponse(w http.ResponseWriter, page hal.Page) { + w.Header().Set("Content-Type", "application/hal+json; charset=utf-8") encoder := json.NewEncoder(w) encoder.SetIndent("", " ") err := encoder.Encode(page) if err != nil { log.Error(err) sendErrorResponse(w, http.StatusInternalServerError, "") - } else { - w.Header().Set("Content-Type", "application/hal+json; charset=utf-8") } } func sendErrorResponse(w http.ResponseWriter, errorCode int, errorMsg string) { - if errorMsg != "" { - http.Error(w, fmt.Sprintf("Error: %s", errorMsg), errorCode) - } else { - http.Error(w, string(serverError), errorCode) + if errorMsg == "" { + errorMsg = string(serverError) + } + + w.Header().Set("Content-Type", "application/json; charset=utf-8") + + // TODO: Use Horizon's existing Problem + errBlob := struct { + Message string `json:"error"` + Status int `json:"status"` + }{ + Message: errorMsg, + Status: errorCode, + } + + encoder := json.NewEncoder(w) + encoder.SetIndent("", " ") + if err := encoder.Encode(errBlob); err != nil { + log.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) } }