diff --git a/handlers.go b/handlers.go index c9d7979..63606b4 100644 --- a/handlers.go +++ b/handlers.go @@ -42,9 +42,19 @@ func (app *application) metadataHandler(w http.ResponseWriter, r *http.Request) w.Header().Add("Content-Type", "application/json") - w.Write(output) + _, err = w.Write(output) + if err != nil { + app.logger.Error(err.Error()) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } } func (app *application) healthCheckHandler(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("okay!")) + _, err := w.Write([]byte("okay!")) + if err != nil { + app.logger.Error(err.Error()) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } } diff --git a/main.go b/main.go index 070e211..1709518 100644 --- a/main.go +++ b/main.go @@ -17,5 +17,7 @@ func main() { logger: logger, } - http.ListenAndServe(":80", app.routes()) + err := http.ListenAndServe(":80", app.routes()) + logger.Error(err.Error()) + os.Exit(1) }