From 729fbecae61c8c428f111a13944b9c932c2fd2ea Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 17 Jan 2025 19:34:49 +0100 Subject: [PATCH] Fix content-type header --- cmd/web/handlers.go | 1 + cmd/web/helpers.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 3eafc49..638591d 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -342,5 +342,6 @@ func (app *application) GetElection(w http.ResponseWriter, r *http.Request, id i return } + w.Header().Set("Content-Type", "application/json") w.Write(response) } diff --git a/cmd/web/helpers.go b/cmd/web/helpers.go index 77970e5..9668ab1 100644 --- a/cmd/web/helpers.go +++ b/cmd/web/helpers.go @@ -10,6 +10,7 @@ import ( func (app *application) serverError(w http.ResponseWriter, r *http.Request, err error) { app.logger.Error(err.Error()) + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusInternalServerError) var response = api.ErrorResponse{ Code: http.StatusInternalServerError, @@ -20,6 +21,7 @@ func (app *application) serverError(w http.ResponseWriter, r *http.Request, err } func (app *application) badRequestError(w http.ResponseWriter, r *http.Request, err error) { + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusBadRequest) var response = api.ErrorResponse{ Code: http.StatusBadRequest, @@ -29,6 +31,7 @@ func (app *application) badRequestError(w http.ResponseWriter, r *http.Request, } func (app *application) clientError(w http.ResponseWriter, status int, message string) { + w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) var response = api.ErrorResponse{ Code: status, @@ -39,6 +42,7 @@ func (app *application) clientError(w http.ResponseWriter, status int, message s } func (app *application) unprocessableEntityError(w http.ResponseWriter, v validator.Validator) { + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusUnprocessableEntity) var response = api.ErrorResponse{ Code: http.StatusUnprocessableEntity,