From 34adfb3e87899412e611128b4814a09edd783732 Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 5 Jan 2024 12:31:33 +0100 Subject: [PATCH] feat: log more information on authentication errors --- client/client.go | 8 ++++---- server/handler.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 01bd05b..53668b4 100644 --- a/client/client.go +++ b/client/client.go @@ -5,11 +5,11 @@ import ( "crypto/rsa" "crypto/sha256" "encoding/json" - "errors" "net/http" "time" jwt "github.com/dgrijalva/jwt-go" + "github.com/pkg/errors" peering "forge.cadoles.com/Cadoles/go-http-peering" "forge.cadoles.com/Cadoles/go-http-peering/crypto" @@ -52,7 +52,7 @@ func (c *Client) Advertise(attrs peering.PeerAttributes) error { case http.StatusConflict: return peering.ErrPeerExists default: - return ErrUnexpectedResponse + return errors.Wrapf(ErrUnexpectedResponse, "unexpected http status code '%d'", res.StatusCode) } } @@ -76,7 +76,7 @@ func (c *Client) UpdateAttributes(attrs peering.PeerAttributes) error { case http.StatusForbidden: return ErrRejected default: - return ErrUnexpectedResponse + return errors.Wrapf(ErrUnexpectedResponse, "unexpected http status code '%d'", res.StatusCode) } } @@ -96,7 +96,7 @@ func (c *Client) Ping() error { case http.StatusForbidden: return ErrRejected default: - return ErrUnexpectedResponse + return errors.Wrapf(ErrUnexpectedResponse, "unexpected http status code '%d'", res.StatusCode) } } diff --git a/server/handler.go b/server/handler.go index a0734c2..a9bc4e7 100644 --- a/server/handler.go +++ b/server/handler.go @@ -34,7 +34,7 @@ func AdvertiseHandler(store peering.Store, key *rsa.PublicKey, funcs ...OptionFu serverClaims, err := assertServerToken(key, serverToken) if err != nil { - logger.Printf("[ERROR] %+v", errors.WithStack(err)) + logger.Printf("[ERROR] %+v", errors.Wrapf(err, "could not validate token '%s'", serverToken)) sendError(w, http.StatusUnauthorized) return }