Refactor error handling
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user