diff --git a/internal/appeal/appeal_service.go b/internal/appeal/appeal_service.go index 05c0af4c8..81eb73bff 100644 --- a/internal/appeal/appeal_service.go +++ b/internal/appeal/appeal_service.go @@ -41,7 +41,7 @@ func (h *appealHandler) onAPIGetBanMessages() gin.HandlerFunc { return func(ctx *gin.Context) { banID, errParam := httphelper.GetInt64Param(ctx, "ban_id") if errParam != nil { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrInvalidParameter) slog.Warn("Got invalid ban_id parameter", log.ErrAttr(errParam), log.HandlerName(2)) return @@ -102,7 +102,7 @@ func (h *appealHandler) editBanMessage() gin.HandlerFunc { msg, errSave := h.appealUsecase.EditBanMessage(ctx, curUser, reportMessageID, req.BodyMD) if errSave != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to save ban appeal message", log.ErrAttr(errSave), log.HandlerName(2)) return @@ -143,7 +143,7 @@ func (h *appealHandler) onAPIGetAppeals() gin.HandlerFunc { bans, errBans := h.appealUsecase.GetAppealsByActivity(ctx, req) if errBans != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to fetch appeals", log.ErrAttr(errBans)) return diff --git a/internal/asset/asset_service.go b/internal/asset/asset_service.go index 7a3fe14c4..299055bc0 100644 --- a/internal/asset/asset_service.go +++ b/internal/asset/asset_service.go @@ -48,7 +48,7 @@ func (h mediaHandler) onAPISaveMedia() gin.HandlerFunc { mediaFile, errOpen := req.File.Open() if errOpen != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to open form file", log.ErrAttr(errOpen), handlerName) return @@ -60,7 +60,7 @@ func (h mediaHandler) onAPISaveMedia() gin.HandlerFunc { media, errMedia := h.assets.Create(ctx, httphelper.CurrentUserProfile(ctx).SteamID, "media", req.Name, mediaFile) if errMedia != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, errMedia) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, errMedia) slog.Error("Failed to create new asset", log.ErrAttr(errMedia), handlerName) return @@ -76,7 +76,7 @@ func (h mediaHandler) onGetByUUID() gin.HandlerFunc { return func(ctx *gin.Context) { mediaID, idErr := httphelper.GetUUIDParam(ctx, "asset_id") if idErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) slog.Error("Got invalid asset_id", handlerName) return @@ -84,7 +84,7 @@ func (h mediaHandler) onGetByUUID() gin.HandlerFunc { asset, reader, errGet := h.assets.Get(ctx, mediaID) if errGet != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, errGet) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, errGet) slog.Error("Failed to load asset", slog.String("asset_id", mediaID.String()), handlerName) return @@ -93,7 +93,7 @@ func (h mediaHandler) onGetByUUID() gin.HandlerFunc { if asset.IsPrivate { user := httphelper.CurrentUserProfile(ctx) if !user.SteamID.Valid() && (user.SteamID == asset.AuthorID || user.HasPermission(domain.PModerator)) { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) slog.Warn("Tried to access private asset", slog.String("asset_id", mediaID.String()), handlerName) return diff --git a/internal/auth/auth_service.go b/internal/auth/auth_service.go index 94cc13a5a..1e9f4ddbe 100644 --- a/internal/auth/auth_service.go +++ b/internal/auth/auth_service.go @@ -165,7 +165,7 @@ func (h authHandler) onAPILogout() gin.HandlerFunc { return func(ctx *gin.Context) { fingerprint, errCookie := ctx.Cookie(domain.FingerprintCookieName) if errCookie != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, nil) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, nil) slog.Warn("Failed to get fingerprint", handlerName) return @@ -184,14 +184,14 @@ func (h authHandler) onAPILogout() gin.HandlerFunc { personAuth := domain.PersonAuth{} if errGet := h.authUsecase.GetPersonAuthByRefreshToken(ctx, fingerprint, &personAuth); errGet != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, nil) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, nil) slog.Warn("Failed to load person via fingerprint", handlerName) return } if errDelete := h.authUsecase.DeletePersonAuth(ctx, personAuth.PersonAuthID); errDelete != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, nil) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, nil) slog.Error("Failed to delete person auth on logout", log.ErrAttr(errDelete), handlerName) return diff --git a/internal/ban/ban_asn_service.go b/internal/ban/ban_asn_service.go index 2486ce909..25d404148 100644 --- a/internal/ban/ban_asn_service.go +++ b/internal/ban/ban_asn_service.go @@ -64,7 +64,7 @@ func (h banASNHandler) onAPIGetBansASN() gin.HandlerFunc { bansASN, errBans := h.banASN.Get(ctx, req) if errBans != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to fetch banASN", log.ErrAttr(errBans)) return @@ -78,7 +78,7 @@ func (h banASNHandler) onAPIDeleteBansASN() gin.HandlerFunc { return func(ctx *gin.Context) { asnID, asnIDErr := httphelper.GetInt64Param(ctx, "asn_id") if asnIDErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) return } @@ -103,7 +103,7 @@ func (h banASNHandler) onAPIPostBansASNUpdate() gin.HandlerFunc { return func(ctx *gin.Context) { asnID, asnIDErr := httphelper.GetInt64Param(ctx, "asn_id") if asnIDErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) return } diff --git a/internal/ban/ban_net_service.go b/internal/ban/ban_net_service.go index f60021cfd..11e702bfd 100644 --- a/internal/ban/ban_net_service.go +++ b/internal/ban/ban_net_service.go @@ -37,7 +37,7 @@ func (h banNetHandler) onAPIExportBansValveIP() gin.HandlerFunc { return func(ctx *gin.Context) { bans, errBans := h.bans.Get(ctx, domain.CIDRBansQueryFilter{}) if errBans != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) return } @@ -87,7 +87,7 @@ func (h banNetHandler) onAPIPostBansCIDRCreate() gin.HandlerFunc { if errBanCIDR := domain.NewBanCIDR(sid, targetID, duration, req.Reason, req.ReasonText, req.Note, domain.Web, req.CIDR, domain.Banned, &banCIDR); errBanCIDR != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) slog.Warn("Failed to create new ban cidr", log.ErrAttr(errBanCIDR)) return @@ -95,12 +95,12 @@ func (h banNetHandler) onAPIPostBansCIDRCreate() gin.HandlerFunc { if errBan := h.bans.Ban(ctx, &banCIDR); errBan != nil { if errors.Is(errBan, domain.ErrDuplicate) { - httphelper.ResponseApiErr(ctx, http.StatusConflict, domain.ErrDuplicate) + httphelper.ResponseAPIErr(ctx, http.StatusConflict, domain.ErrDuplicate) return } - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to save cidr ban", log.ErrAttr(errBan)) return @@ -124,7 +124,7 @@ func (h banNetHandler) onAPIGetBansCIDR() gin.HandlerFunc { bans, errBans := h.bans.Get(ctx, req) if errBans != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to fetch cidr bans", log.ErrAttr(errBans)) return @@ -138,7 +138,7 @@ func (h banNetHandler) onAPIDeleteBansCIDR() gin.HandlerFunc { return func(ctx *gin.Context) { netID, netIDErr := httphelper.GetInt64Param(ctx, "net_id") if netIDErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) return } @@ -164,7 +164,7 @@ func (h banNetHandler) onAPIPostBansCIDRUpdate() gin.HandlerFunc { return func(ctx *gin.Context) { netID, banIDErr := httphelper.GetInt64Param(ctx, "net_id") if banIDErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) return } diff --git a/internal/blocklist/blocklist_service.go b/internal/blocklist/blocklist_service.go index 16a4a7722..ed5f326d7 100644 --- a/internal/blocklist/blocklist_service.go +++ b/internal/blocklist/blocklist_service.go @@ -86,7 +86,7 @@ func (b *blocklistHandler) onAPICreateWhitelistSteam() gin.HandlerFunc { steamID, ok := req.SteamID(ctx) if !ok { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidSID) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidSID) slog.Warn("Got invalid steamid", slog.String("steam_id", req.SteamIDValue)) return @@ -232,7 +232,7 @@ func (b *blocklistHandler) onAPIPostBlockListUpdate() gin.HandlerFunc { blockSource, errUpdate := b.blocklists.UpdateCIDRBlockSource(ctx, sourceID, req.Name, req.URL, req.Enabled) if errUpdate != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) return } diff --git a/internal/chat/chat_service.go b/internal/chat/chat_service.go index 060890943..a1fe13115 100644 --- a/internal/chat/chat_service.go +++ b/internal/chat/chat_service.go @@ -44,7 +44,7 @@ func (h chatHandler) onAPIQueryMessages() gin.HandlerFunc { if errChat != nil && !errors.Is(errChat, domain.ErrNoResult) { slog.Error("Failed to query messages history", log.ErrAttr(errChat), slog.String("sid", req.SourceID)) - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) return } @@ -57,7 +57,7 @@ func (h chatHandler) onAPIQueryMessageContext() gin.HandlerFunc { return func(ctx *gin.Context) { messageID, errMessageID := httphelper.GetInt64Param(ctx, "person_message_id") if errMessageID != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) slog.Debug("Got invalid person_message_id", log.ErrAttr(errMessageID)) return @@ -65,7 +65,7 @@ func (h chatHandler) onAPIQueryMessageContext() gin.HandlerFunc { padding, errPadding := httphelper.GetIntParam(ctx, "padding") if errPadding != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) slog.Debug("Got invalid padding", log.ErrAttr(errPadding)) return @@ -73,7 +73,7 @@ func (h chatHandler) onAPIQueryMessageContext() gin.HandlerFunc { messages, errQuery := h.chat.GetPersonMessageContext(ctx, messageID, padding) if errQuery != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) return } diff --git a/internal/contest/contest_service.go b/internal/contest/contest_service.go index 71c3017bf..fb7c04624 100644 --- a/internal/contest/contest_service.go +++ b/internal/contest/contest_service.go @@ -76,7 +76,7 @@ func (c *contestHandler) contestFromCtx(ctx *gin.Context) (domain.Contest, bool) } if !contest.Public && httphelper.CurrentUserProfile(ctx).PermissionLevel < domain.PModerator { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrNotFound) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrNotFound) return domain.Contest{}, false } @@ -165,7 +165,7 @@ func (c *contestHandler) onAPIDeleteContest() gin.HandlerFunc { if errContest := c.contests.ContestByID(ctx, contestID, &contest); errContest != nil { if errors.Is(errContest, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrUnknownID) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrUnknownID) return } @@ -240,7 +240,7 @@ func (c *contestHandler) onAPISaveContestEntryMedia() gin.HandlerFunc { } if !slices.Contains(strings.Split(strings.ToLower(contest.MediaTypes), ","), strings.ToLower(mimeType.String())) { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrMimeTypeNotAllowed) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrMimeTypeNotAllowed) slog.Warn("User tried to upload file with disallowed mime type", slog.String("mime", strings.ToLower(mimeType.String()))) return @@ -331,7 +331,7 @@ func (c *contestHandler) onAPISaveContestEntrySubmit() gin.HandlerFunc { existingEntries, errEntries := c.contests.ContestEntries(ctx, contest.ContestID) if errEntries != nil && !errors.Is(errEntries, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrContestLoadEntries) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrContestLoadEntries) return } @@ -344,7 +344,7 @@ func (c *contestHandler) onAPISaveContestEntrySubmit() gin.HandlerFunc { } if own >= contest.MaxSubmissions { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrContestMaxEntries) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrContestMaxEntries) return } @@ -354,26 +354,26 @@ func (c *contestHandler) onAPISaveContestEntrySubmit() gin.HandlerFunc { asset, _, errAsset := c.assets.Get(ctx, req.AssetID) if errAsset != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrEntryCreate) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrEntryCreate) return } if asset.AuthorID != steamID { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) return } entry, errEntry := contest.NewEntry(steamID, req.AssetID, req.Description) if errEntry != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrEntryCreate) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrEntryCreate) return } if errSave := c.contests.ContestEntrySave(ctx, entry); errSave != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrEntrySave) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrEntrySave) return } @@ -390,7 +390,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { contestEntryID, idErr := httphelper.GetUUIDParam(ctx, "contest_entry_id") if idErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) return } @@ -399,12 +399,12 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { if errContest := c.contests.ContestEntry(ctx, contestEntryID, &entry); errContest != nil { if errors.Is(errContest, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrUnknownID) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrUnknownID) return } - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) slog.Error("Error getting contest entry for deletion", log.ErrAttr(errContest)) @@ -413,7 +413,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { // Only >=moderators or the entry author are allowed to delete entries. if !(user.PermissionLevel >= domain.PModerator || user.SteamID == entry.SteamID) { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) return } @@ -422,12 +422,12 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { if errContest := c.contests.ContestByID(ctx, entry.ContestID, &contest); errContest != nil { if errors.Is(errContest, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrUnknownID) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrUnknownID) return } - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) slog.Error("Error getting contest", log.ErrAttr(errContest)) @@ -436,7 +436,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { // Only allow mods to delete entries from expired contests. if user.SteamID == entry.SteamID && time.Since(contest.DateEnd) > 0 { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) slog.Error("User tried to delete entry from expired contest") @@ -444,7 +444,7 @@ func (c *contestHandler) onAPIDeleteContestEntry() gin.HandlerFunc { } if errDelete := c.contests.ContestEntryDelete(ctx, entry.ContestEntryID); errDelete != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Error deleting contest entry", log.ErrAttr(errDelete)) diff --git a/internal/demo/demo_service.go b/internal/demo/demo_service.go index 16b9a88f8..c96aadfb7 100644 --- a/internal/demo/demo_service.go +++ b/internal/demo/demo_service.go @@ -35,7 +35,7 @@ func (h demoHandler) onAPIPostDemosQuery() gin.HandlerFunc { return func(ctx *gin.Context) { demos, errDemos := h.demos.GetDemos(ctx) if errDemos != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to query demos", log.ErrAttr(errDemos)) return diff --git a/internal/discord/discord_service_oauth.go b/internal/discord/discord_service_oauth.go index 93c687e33..a37658d13 100644 --- a/internal/discord/discord_service_oauth.go +++ b/internal/discord/discord_service_oauth.go @@ -47,7 +47,7 @@ func (h discordOAuthHandler) onLogin() gin.HandlerFunc { loginURL, errURL := h.discord.CreateStatefulLoginURL(currentUser.SteamID) if errURL != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, nil) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, nil) slog.Error("Failed to get state from query") return @@ -91,12 +91,12 @@ func (h discordOAuthHandler) onGetDiscordUser() gin.HandlerFunc { discord, errUser := h.discord.GetUserDetail(ctx, user.SteamID) if errUser != nil { if errors.Is(errUser, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrNotFound) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrNotFound) return } - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Error trying to fetch discord user details", log.ErrAttr(errUser)) return @@ -118,7 +118,7 @@ func (h discordOAuthHandler) onLogout() gin.HandlerFunc { return } - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Error trying to logout discord user", log.ErrAttr(errUser)) return diff --git a/internal/forum/forum_service.go b/internal/forum/forum_service.go index c9eb8a9b4..21baca325 100644 --- a/internal/forum/forum_service.go +++ b/internal/forum/forum_service.go @@ -278,13 +278,13 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { } if len(req.BodyMD) <= 1 { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, fmt.Errorf("body: %w", domain.ErrTooShort)) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, fmt.Errorf("body: %w", domain.ErrTooShort)) return } if len(req.Title) <= 4 { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, fmt.Errorf("title: %w", domain.ErrTooShort)) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, fmt.Errorf("title: %w", domain.ErrTooShort)) return } @@ -317,7 +317,7 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { slog.Error("Failed to rollback new thread", log.ErrAttr(errRollback)) } - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to save new forum message", log.ErrAttr(errSaveMessage)) @@ -325,7 +325,7 @@ func (f *forumHandler) onAPIThreadCreate() gin.HandlerFunc { } if errIncr := f.forums.ForumIncrMessageCount(ctx, forum.ForumID, true); errIncr != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to increment message count", log.ErrAttr(errIncr)) @@ -373,7 +373,7 @@ func (f *forumHandler) onAPIThreadUpdate() gin.HandlerFunc { var thread domain.ForumThread if errGet := f.forums.ForumThread(ctx, forumThreadID, &thread); errGet != nil { if errors.Is(errGet, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrNotFound) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrNotFound) slog.Warn("Requested unknown forum thread", log.ErrAttr(errGet)) } else { httphelper.HandleErrInternal(ctx) @@ -394,7 +394,7 @@ func (f *forumHandler) onAPIThreadUpdate() gin.HandlerFunc { thread.Locked = req.Locked if errDelete := f.forums.ForumThreadSave(ctx, &thread); errDelete != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to update thread", log.ErrAttr(errDelete)) return @@ -467,7 +467,7 @@ func (f *forumHandler) onAPIThreadMessageUpdate() gin.HandlerFunc { forumMessageID, errForumMessageID := httphelper.GetInt64Param(ctx, "forum_message_id") if errForumMessageID != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) slog.Warn("Failed to get forum_message_id", log.ErrAttr(errForumMessageID)) return @@ -550,7 +550,7 @@ func (f *forumHandler) onAPIMessageDelete() gin.HandlerFunc { } if thread.Locked { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrThreadLocked) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrThreadLocked) return } @@ -632,7 +632,7 @@ func (f *forumHandler) onAPIThreadCreateReply() gin.HandlerFunc { } if thread.Locked && currentUser.PermissionLevel < domain.PEditor { - httphelper.ResponseApiErr(ctx, http.StatusForbidden, domain.ErrThreadLocked) + httphelper.ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrThreadLocked) return } @@ -645,7 +645,7 @@ func (f *forumHandler) onAPIThreadCreateReply() gin.HandlerFunc { req.BodyMD = stringutil.SanitizeUGC(req.BodyMD) if len(req.BodyMD) < 3 { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, fmt.Errorf("body: %w", domain.ErrTooShort)) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, fmt.Errorf("body: %w", domain.ErrTooShort)) return } @@ -700,7 +700,7 @@ func (f *forumHandler) onAPIForumOverview() gin.HandlerFunc { currentForums, errForums := f.forums.Forums(ctx) if errForums != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Could not load forums", log.ErrAttr(errForums)) return @@ -787,7 +787,7 @@ func (f *forumHandler) onAPIForumThread() gin.HandlerFunc { if errors.Is(errThreads, domain.ErrNoResult) { httphelper.HandleErrNotFound(ctx) } else { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Could not load threads", log.ErrAttr(errThreads), slog.Int64("forum_thread_id", forumThreadID)) } diff --git a/internal/httphelper/http.go b/internal/httphelper/http.go index e51c57f80..af1ff41b4 100644 --- a/internal/httphelper/http.go +++ b/internal/httphelper/http.go @@ -103,27 +103,27 @@ func HandleErrs(ctx *gin.Context, err error) { } func HandleErrPermissionDenied(ctx *gin.Context) { - ResponseApiErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) + ResponseAPIErr(ctx, http.StatusForbidden, domain.ErrPermissionDenied) } func HandleErrNotFound(ctx *gin.Context) { - ResponseApiErr(ctx, http.StatusNotFound, domain.ErrNotFound) + ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrNotFound) } func HandleErrBadRequest(ctx *gin.Context) { - ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) + ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrBadRequest) } func HandleErrInternal(ctx *gin.Context) { - ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) } func HandleErrDuplicate(ctx *gin.Context) { - ResponseApiErr(ctx, http.StatusConflict, domain.ErrDuplicate) + ResponseAPIErr(ctx, http.StatusConflict, domain.ErrDuplicate) } func HandleErrInvalidFormat(ctx *gin.Context) { - ResponseApiErr(ctx, http.StatusUnsupportedMediaType, domain.ErrInvalidFormat) + ResponseAPIErr(ctx, http.StatusUnsupportedMediaType, domain.ErrInvalidFormat) } func useSentry(engine *gin.Engine, version string) { diff --git a/internal/match/match_service.go b/internal/match/match_service.go index c3d0129b7..42e8da1f5 100644 --- a/internal/match/match_service.go +++ b/internal/match/match_service.go @@ -62,7 +62,7 @@ func (h matchHandler) onAPIPostMatchEnd() gin.HandlerFunc { matchUUID, errEnd := h.matches.EndMatch(ctx, serverID) if errEnd != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) slog.Error("Failed to end match", log.ErrAttr(errEnd)) return @@ -90,7 +90,7 @@ func (h matchHandler) onAPIPostMatchStart() gin.HandlerFunc { serverID, errServerID := httphelper.GetIntParam(ctx, "server_id") if errServerID != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) slog.Warn("Failed to get server_id", log.ErrAttr(errServerID)) return @@ -98,7 +98,7 @@ func (h matchHandler) onAPIPostMatchStart() gin.HandlerFunc { server, errServer := h.servers.Server(ctx, serverID) if errServer != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) slog.Error("Failed to get server", log.ErrAttr(errServer)) return @@ -106,7 +106,7 @@ func (h matchHandler) onAPIPostMatchStart() gin.HandlerFunc { matchUUID, errMatch := h.matches.StartMatch(server, req.MapName, req.DemoName) if errMatch != nil { - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrUnknownServerID) slog.Error("Failed to start match", log.ErrAttr(errMatch)) return @@ -148,7 +148,7 @@ func (h matchHandler) onAPIGetsStatsWeapon() gin.HandlerFunc { return func(ctx *gin.Context) { weaponID, errWeaponID := httphelper.GetIntParam(ctx, "weapon_id") if errWeaponID != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) slog.Warn("Failed to get weapon_id", log.ErrAttr(errWeaponID)) return @@ -307,7 +307,7 @@ func (h matchHandler) onAPIGetMatch() gin.HandlerFunc { return func(ctx *gin.Context) { matchID, errID := httphelper.GetUUIDParam(ctx, "match_id") if errID != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) slog.Warn("Failed to get match_id", log.ErrAttr(errID)) return @@ -319,7 +319,7 @@ func (h matchHandler) onAPIGetMatch() gin.HandlerFunc { if errMatch != nil { if errors.Is(errMatch, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrNotFound) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrNotFound) return } diff --git a/internal/network/network_service.go b/internal/network/network_service.go index a36192813..47dd854dd 100644 --- a/internal/network/network_service.go +++ b/internal/network/network_service.go @@ -65,7 +65,7 @@ func (h networkHandler) onAPIQueryNetwork() gin.HandlerFunc { details, err := h.networks.QueryNetwork(ctx, req.IP) if err != nil { slog.Error("Failed to query connection history", log.ErrAttr(err)) - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) return } diff --git a/internal/patreon/patreon_service.go b/internal/patreon/patreon_service.go index d11b97c29..dad945b1d 100644 --- a/internal/patreon/patreon_service.go +++ b/internal/patreon/patreon_service.go @@ -44,7 +44,7 @@ func (h patreonHandler) onLogout() gin.HandlerFunc { currentUser := httphelper.CurrentUserProfile(ctx) if err := h.patreon.Forget(ctx, currentUser.SteamID); err != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, nil) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, nil) return } @@ -67,14 +67,14 @@ func (h patreonHandler) onOAuth() gin.HandlerFunc { return func(ctx *gin.Context) { grantCode, codeOK := ctx.GetQuery("code") if !codeOK { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, nil) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, nil) return } state, stateOK := ctx.GetQuery("state") if !stateOK { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, nil) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, nil) return } diff --git a/internal/report/report_service.go b/internal/report/report_service.go index 4c44c3f57..50ef48333 100644 --- a/internal/report/report_service.go +++ b/internal/report/report_service.go @@ -59,7 +59,7 @@ func (h reportHandler) onAPIPostReportCreate() gin.HandlerFunc { report, errReportSave := h.reports.SaveReport(ctx, currentUser, req) if errReportSave != nil { if errors.Is(errReportSave, domain.ErrReportExists) { - httphelper.ResponseApiErr(ctx, http.StatusConflict, domain.ErrReportExists) + httphelper.ResponseAPIErr(ctx, http.StatusConflict, domain.ErrReportExists) return } diff --git a/internal/srcds/srcds_service.go b/internal/srcds/srcds_service.go index 66da52457..3783aaf6a 100644 --- a/internal/srcds/srcds_service.go +++ b/internal/srcds/srcds_service.go @@ -398,7 +398,7 @@ func (s *srcdsHandler) onDeleteGroupOverride() gin.HandlerFunc { if err := s.srcds.DelGroupOverride(ctx, groupOverrideID); err != nil { if errors.Is(err, domain.ErrNoResult) { - httphelper.ResponseApiErr(ctx, http.StatusNotFound, domain.ErrNotFound) + httphelper.ResponseAPIErr(ctx, http.StatusNotFound, domain.ErrNotFound) return } @@ -862,12 +862,12 @@ func (s *srcdsHandler) onAPIPostBanSteamCreate() gin.HandlerFunc { ban, errBan := s.bans.Ban(ctx, httphelper.CurrentUserProfile(ctx), domain.InGame, req) if errBan != nil { if errors.Is(errBan, domain.ErrDuplicate) { - httphelper.ResponseApiErr(ctx, http.StatusConflict, domain.ErrDuplicate) + httphelper.ResponseAPIErr(ctx, http.StatusConflict, domain.ErrDuplicate) return } - httphelper.ResponseApiErr(ctx, http.StatusInternalServerError, domain.ErrInternal) + httphelper.ResponseAPIErr(ctx, http.StatusInternalServerError, domain.ErrInternal) slog.Error("Failed to save new steam ban", log.ErrAttr(errBan)) return diff --git a/internal/steamgroup/steamgroup_service.go b/internal/steamgroup/steamgroup_service.go index 20501c671..5d810cb86 100644 --- a/internal/steamgroup/steamgroup_service.go +++ b/internal/steamgroup/steamgroup_service.go @@ -102,7 +102,7 @@ func (h steamgroupHandler) onAPIPostBansGroupUpdate() gin.HandlerFunc { return func(ctx *gin.Context) { banGroupID, banIDErr := httphelper.GetInt64Param(ctx, "ban_group_id") if banIDErr != nil { - httphelper.ResponseApiErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) + httphelper.ResponseAPIErr(ctx, http.StatusBadRequest, domain.ErrInvalidParameter) slog.Warn("Failed to get ban_group_id", log.ErrAttr(banIDErr)) return