Commit f4330099 authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Add error logging to SSO authentication middleware

- Integrate zerolog for detailed error logging in AuthMiddleware
- Log errors when reading SSO response body or unmarshaling response
- Improve error traceability during authentication process
parent 0fd78686
......@@ -6,6 +6,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
"gitlab.com/tensorsecurity-rd/waf-console/internal/utils"
)
......@@ -56,6 +57,7 @@ func AuthMiddleware(ssoUrl string) gin.HandlerFunc {
// Read response body
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Error().Err(err).Msg("failed to read sso response body")
utils.AssembleResponse(c, nil, utils.ErrInternalServer)
c.Abort()
return
......@@ -64,6 +66,7 @@ func AuthMiddleware(ssoUrl string) gin.HandlerFunc {
// Parse SSO response
var ssoResp SSOResponse
if err := json.Unmarshal(body, &ssoResp); err != nil {
log.Error().Err(err).Msg("failed to unmarshal sso response")
utils.AssembleResponse(c, nil, utils.ErrInternalServer)
c.Abort()
return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment