feat(account): #49 refactor error handling
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m19s

This commit is contained in:
2025-05-08 21:45:53 +02:00
parent 511c4ca22b
commit bd18453a6e
8 changed files with 118 additions and 74 deletions

21
handler/error.go Normal file
View File

@@ -0,0 +1,21 @@
package handler
import (
"errors"
"net/http"
"spend-sparrow/service"
"spend-sparrow/utils"
)
func handleError(w http.ResponseWriter, r *http.Request, err error) {
if errors.Is(err, service.ErrUnauthorized) {
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)
return
}
utils.TriggerToastWithStatus(w, r, "error", "Internal Server Error", http.StatusInternalServerError)
}