Refactor error handling

This commit is contained in:
waseem-medhat
2025-03-13 15:10:43 +02:00
parent 59115e60e9
commit 2a2dc863bd
4 changed files with 18 additions and 23 deletions

View File

@@ -13,13 +13,13 @@ func (cfg *apiConfig) middlewareAuth(handler authedHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
apiKey, err := auth.GetAPIKey(r.Header)
if err != nil {
respondWithError(w, http.StatusUnauthorized, "Couldn't find api key")
respondWithError(w, http.StatusUnauthorized, "Couldn't find api key", err)
return
}
user, err := cfg.DB.GetUser(r.Context(), apiKey)
if err != nil {
respondWithError(w, http.StatusNotFound, "Couldn't get user")
respondWithError(w, http.StatusNotFound, "Couldn't get user", err)
return
}