mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-28 21:39:26 +02:00
error responses always lower case + duplicate error response fix
This commit is contained in:
parent
931c20c8fe
commit
d3de035961
@ -58,7 +58,7 @@ func (m *AuthMiddleware) Handler(h http.Handler) http.Handler {
|
|||||||
err := m.CheckJWTFromRequest(w, r)
|
err := m.CheckJWTFromRequest(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Error when validating JWT claims: %s", err.Error())
|
log.Debugf("Error when validating JWT claims: %s", err.Error())
|
||||||
util.WriteError(status.Errorf(status.Unauthorized, "Token invalid"), w)
|
util.WriteError(status.Errorf(status.Unauthorized, "token invalid"), w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
@ -66,12 +66,12 @@ func (m *AuthMiddleware) Handler(h http.Handler) http.Handler {
|
|||||||
err := m.CheckPATFromRequest(w, r)
|
err := m.CheckPATFromRequest(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Error when validating PAT claims: %s", err.Error())
|
log.Debugf("Error when validating PAT claims: %s", err.Error())
|
||||||
util.WriteError(status.Errorf(status.Unauthorized, "Token invalid"), w)
|
util.WriteError(status.Errorf(status.Unauthorized, "token invalid"), w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
default:
|
default:
|
||||||
util.WriteError(status.Errorf(status.Unauthorized, "No valid authentication provided"), w)
|
util.WriteError(status.Errorf(status.Unauthorized, "no valid authentication provided"), w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -115,11 +115,9 @@ func (m *AuthMiddleware) CheckPATFromRequest(w http.ResponseWriter, r *http.Requ
|
|||||||
|
|
||||||
account, user, pat, err := m.getAccountFromPAT(token)
|
account, user, pat, err := m.getAccountFromPAT(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.WriteError(status.Errorf(status.Unauthorized, "Token invalid"), w)
|
|
||||||
return fmt.Errorf("invalid Token: %w", err)
|
return fmt.Errorf("invalid Token: %w", err)
|
||||||
}
|
}
|
||||||
if time.Now().After(pat.ExpirationDate) {
|
if time.Now().After(pat.ExpirationDate) {
|
||||||
util.WriteError(status.Errorf(status.Unauthorized, "Token expired"), w)
|
|
||||||
return fmt.Errorf("token expired")
|
return fmt.Errorf("token expired")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -99,7 +100,7 @@ func WriteError(err error, w http.ResponseWriter) {
|
|||||||
httpStatus = http.StatusUnauthorized
|
httpStatus = http.StatusUnauthorized
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
msg = err.Error()
|
msg = strings.ToLower(err.Error())
|
||||||
} else {
|
} else {
|
||||||
unhandledMSG := fmt.Sprintf("got unhandled error code, error: %s", err.Error())
|
unhandledMSG := fmt.Sprintf("got unhandled error code, error: %s", err.Error())
|
||||||
log.Error(unhandledMSG)
|
log.Error(unhandledMSG)
|
||||||
|
Loading…
Reference in New Issue
Block a user