From 48bb33c33f8f9076ea59de8fe51196fee4d1dfff Mon Sep 17 00:00:00 2001 From: San Date: Fri, 27 Dec 2024 14:40:05 -0300 Subject: [PATCH] return non 404 error when the session does not exists --- gateway/api/session/session.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gateway/api/session/session.go b/gateway/api/session/session.go index d1705cee..b306063a 100644 --- a/gateway/api/session/session.go +++ b/gateway/api/session/session.go @@ -351,19 +351,18 @@ func Get(c *gin.Context) { sessionID := c.Param("session_id") session, err := models.GetSessionByID(ctx.OrgID, sessionID) - if err != nil { + switch err { + case models.ErrNotFound: + c.JSON(http.StatusNotFound, gin.H{"message": "not found"}) + return + case nil: + default: log.Errorf("failed fetching session, err=%v", err) sentry.CaptureException(err) c.JSON(http.StatusInternalServerError, gin.H{"message": "failed fetching session"}) return } - // if not found, return 404 - if session == nil { - c.JSON(http.StatusNotFound, gin.H{"message": "not found"}) - return - } - // if user is not admin or auditor and session is not owned by user, return 404 if session.UserID != ctx.UserID && !ctx.IsAuditorOrAdminUser() { c.JSON(http.StatusNotFound, gin.H{"message": "not found"})