added error wrapping to auth middleware for better stacktrace
This commit is contained in:
@@ -2,10 +2,12 @@ package hwsauth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.haelnorr.com/h/golib/hws"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.haelnorr.com/h/golib/hws"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Authenticate returns the main authentication middleware.
|
// Authenticate returns the main authentication middleware.
|
||||||
@@ -30,12 +32,20 @@ func (auth *Authenticator[T, TX]) authenticate() hws.MiddlewareFunc {
|
|||||||
// Start the transaction
|
// Start the transaction
|
||||||
tx, err := auth.beginTx(ctx)
|
tx, err := auth.beginTx(ctx)
|
||||||
if err != nil {
|
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
|
// Type assert to TX - safe because user's beginTx should return their TX type
|
||||||
txTyped, ok := tx.(TX)
|
txTyped, ok := tx.(TX)
|
||||||
if !ok {
|
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)
|
model, err := auth.getAuthenticatedUser(txTyped, w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user