Properly handle error and improve error messages

This commit is contained in:
2024-09-21 11:26:25 +07:00
parent 557e7313b2
commit bcdcbd5049
25 changed files with 258 additions and 234 deletions

View File

@ -1,7 +1,6 @@
package logoutHandler
import (
"errors"
"github.com/fossyy/filekeeper/app"
"github.com/fossyy/filekeeper/types"
"net/http"
@ -14,25 +13,23 @@ func GET(w http.ResponseWriter, r *http.Request) {
userSession := r.Context().Value("user").(types.User)
cookie, err := r.Cookie("Session")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
app.Server.Logger.Error(err.Error())
return
}
storeSession := session.Get(cookie.Value)
if err != nil {
if errors.Is(err, &session.SessionNotFoundError{}) {
storeSession.Destroy(w)
}
w.WriteHeader(http.StatusInternalServerError)
return
}
err = storeSession.Delete()
if err != nil {
app.Server.Logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
app.Server.Logger.Error(err.Error())
return
}
err = session.RemoveSessionInfo(userSession.Email, cookie.Value)
if err != nil {
app.Server.Logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
app.Server.Logger.Error(err.Error())
return
}