feat(account): #49 refactor error handling
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 3m55s

This commit is contained in:
2025-05-08 22:58:14 +02:00
parent bd18453a6e
commit fecf53fd20
10 changed files with 39 additions and 58 deletions

View File

@@ -3,9 +3,9 @@ package handler
import (
"errors"
"net/http"
"spend-sparrow/service"
"spend-sparrow/utils"
"strings"
)
func handleError(w http.ResponseWriter, r *http.Request, err error) {
@@ -13,9 +13,18 @@ func handleError(w http.ResponseWriter, r *http.Request, err error) {
utils.TriggerToastWithStatus(w, r, "error", "You are not autorized to perform this operation.", http.StatusUnauthorized)
return
} else if errors.Is(err, service.ErrBadRequest) {
utils.TriggerToastWithStatus(w, r, "error", err.Error(), http.StatusBadRequest)
utils.TriggerToastWithStatus(w, r, "error", extractErrorMessage(err), http.StatusBadRequest)
return
}
utils.TriggerToastWithStatus(w, r, "error", "Internal Server Error", http.StatusInternalServerError)
}
func extractErrorMessage(err error) string {
errMsg := err.Error()
if errMsg == "" {
return ""
}
return strings.SplitN(errMsg, ":", 2)[0]
}