Second checkpoint

This commit is contained in:
2026-06-25 01:17:42 +05:00
parent 854ef138d0
commit 9cf791b789
90 changed files with 5504 additions and 988 deletions

View File

@@ -0,0 +1,24 @@
package http
import (
"errors"
"net/http"
"gis/internal/domain"
"gis/pkg/httputil"
)
// respondDomainError maps a domain error to an HTTP status and writes a JSON
// error envelope.
func respondDomainError(w http.ResponseWriter, err error) {
switch {
case errors.Is(err, domain.ErrNotFound):
httputil.WriteError(w, http.StatusNotFound, "not found")
case errors.Is(err, domain.ErrValidation):
httputil.WriteError(w, http.StatusUnprocessableEntity, err.Error())
case errors.Is(err, domain.ErrConflict):
httputil.WriteError(w, http.StatusConflict, "operation conflicts with existing data")
default:
httputil.WriteError(w, http.StatusInternalServerError, "internal server error")
}
}