Files
Foundry-Scrapping-API/cmd/api/errors.go
2026-04-10 18:34:01 +03:00

25 lines
711 B
Go

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)
}