| 162 | } |
| 163 | |
| 164 | func writeAuthSessionError(c *gin.Context, err error) { |
| 165 | status, code := service.AuthSessionErrorCode(err) |
| 166 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 167 | status, code = http.StatusUnauthorized, "AUTH_UNAUTHORIZED" |
| 168 | } |
| 169 | if status == http.StatusInternalServerError { |
| 170 | // The response body only carries the generic AUTH_INTERNAL_ERROR |
| 171 | // code; without this log the underlying Redis/database/session |
| 172 | // failure is indistinguishable from the client side. |
| 173 | logger.LogError(c.Request.Context(), fmt.Sprintf("auth session internal error (%s %s): %v", c.Request.Method, c.Request.URL.Path, err)) |
| 174 | } |
| 175 | c.JSON(status, gin.H{"success": false, "code": code, "message": http.StatusText(status)}) |
| 176 | } |
| 177 | |
| 178 | func setAuthNoStore(c *gin.Context) { |
| 179 | c.Header("Cache-Control", "no-store") |