add healthcheck route
This commit is contained in:
24
cmd/api/errors.go
Normal file
24
cmd/api/errors.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
func (app *application) logError(r *http.Request, err error) {
|
||||
app.slogger.Error(err.Error(), "request_method", r.Method, "request_url", r.URL.String())
|
||||
}
|
||||
|
||||
func (app *application) errorResponse(w http.ResponseWriter, r *http.Request, status int, message any) {
|
||||
env := envelope{"error": message}
|
||||
|
||||
err := app.writeJSON(w, status, env, nil)
|
||||
if err != nil {
|
||||
app.logError(r, err)
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
}
|
||||
|
||||
func (app *application) serverErrorResponse(w http.ResponseWriter, r *http.Request, err error) {
|
||||
app.logError(r, err)
|
||||
|
||||
message := "the server encountered a problem and could not process your request"
|
||||
app.errorResponse(w, r, http.StatusInternalServerError, message)
|
||||
}
|
||||
Reference in New Issue
Block a user