From 7ed40c7afef60d729fbe65102dde6e9e4f659a14 Mon Sep 17 00:00:00 2001 From: Haelnorr Date: Mon, 26 Jan 2026 21:56:47 +1100 Subject: [PATCH] added error wrapping to auth middleware for better stacktrace --- hwsauth/middleware.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hwsauth/middleware.go b/hwsauth/middleware.go index f9dbaad..5a87892 100644 --- a/hwsauth/middleware.go +++ b/hwsauth/middleware.go @@ -2,10 +2,12 @@ package hwsauth import ( "context" - "git.haelnorr.com/h/golib/hws" "net/http" "slices" "time" + + "git.haelnorr.com/h/golib/hws" + "github.com/pkg/errors" ) // Authenticate returns the main authentication middleware. @@ -30,12 +32,20 @@ func (auth *Authenticator[T, TX]) authenticate() hws.MiddlewareFunc { // Start the transaction tx, err := auth.beginTx(ctx) if err != nil { - return nil, &hws.HWSError{Message: "Unable to start transaction", StatusCode: http.StatusServiceUnavailable, Error: err} + return nil, &hws.HWSError{ + Message: "Unable to start transaction", + StatusCode: http.StatusServiceUnavailable, + Error: errors.Wrap(err, "auth.beginTx"), + } } // Type assert to TX - safe because user's beginTx should return their TX type txTyped, ok := tx.(TX) if !ok { - return nil, &hws.HWSError{Message: "Transaction type mismatch", StatusCode: http.StatusInternalServerError, Error: err} + return nil, &hws.HWSError{ + Message: "Transaction type mismatch", + StatusCode: http.StatusInternalServerError, + Error: errors.Wrap(err, "TX type not ok"), + } } model, err := auth.getAuthenticatedUser(txTyped, w, r) if err != nil {