🔊 Add WithLogger so we can log the rendered error

This commit is contained in:
Dan Jones 2024-01-22 10:29:58 -06:00
commit 2324d738bc
3 changed files with 29 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
rErrors "codeberg.org/danjones000/responsable-errors"
@ -117,3 +118,15 @@ func (s *MiddlewareTestSuite) TestNoWorkingTransformer() {
s.Assert().Equal("Unknown Error", outMsg)
s.Assert().Equal(http.StatusInternalServerError, s.w.Code)
}
func (s *MiddlewareTestSuite) TestLogger() {
buff := strings.Builder{}
var l LoggerFunc = func(c *gin.Context, err rErrors.ResponsableError) {
buff.WriteString("Err: " + err.Error())
}
err := errors.New("Foo")
s.ctx.Error(err)
ErrorMiddleware(WithLogger(l))(s.ctx)
s.Assert().Equal("Err: Foo", buff.String())
}