feat: persist data in PostgreSQL and add Basic/Bearer sessions in Redis

This commit is contained in:
2026-10-30 01:34:50 +03:00
parent 196e118ede
commit f68710818d
27 changed files with 1229 additions and 214 deletions
+8 -1
View File
@@ -35,11 +35,18 @@ func (h *Handler) fail(w http.ResponseWriter, r *http.Request, err error) {
case errors.Is(err, domain.ErrInvalidInput):
writeError(w, http.StatusBadRequest, "invalid_request", err.Error())
case errors.Is(err, domain.ErrUnauthorized):
writeError(w, http.StatusUnauthorized, "unauthorized", "valid X-User-Id header is required")
if w.Header().Get(headerWWWAuthenticate) == "" {
w.Header().Set(headerWWWAuthenticate, bearerChallenge)
}
writeError(w, http.StatusUnauthorized, "unauthorized", "valid authentication is required")
case errors.Is(err, domain.ErrNotFound):
writeError(w, http.StatusNotFound, "not_found", "resource not found")
case errors.Is(err, domain.ErrConflict):
writeError(w, http.StatusConflict, "conflict", "username is already taken")
case errors.Is(err, domain.ErrUnavailable):
h.log.Error("dependency unavailable", "request_id", w.Header().Get(headerRequestID),
"method", r.Method, "path", r.URL.Path, "err", err)
writeError(w, http.StatusServiceUnavailable, "unavailable", "service temporarily unavailable")
default:
h.log.Error("unexpected error", "request_id", w.Header().Get(headerRequestID),
"method", r.Method, "path", r.URL.Path, "err", err)