From 500b09516a2b0af4de303f16478c6b48a2b5c188 Mon Sep 17 00:00:00 2001 From: rxdn <29165304+rxdn@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:09:52 +0100 Subject: [PATCH] Don't use abort --- .../endpoints/api/panel/multipanelcreate.go | 2 +- .../endpoints/api/panel/multipanelresend.go | 2 +- .../endpoints/api/panel/multipanelupdate.go | 2 +- app/http/endpoints/api/premium.go | 2 +- app/http/endpoints/api/ticket/closeticket.go | 8 +++---- app/http/endpoints/api/ticket/getticket.go | 10 ++++----- app/http/endpoints/api/ticket/sendmessage.go | 22 +++++++++---------- app/http/endpoints/api/transcripts/get.go | 2 +- app/http/endpoints/api/transcripts/list.go | 2 +- app/http/endpoints/api/transcripts/render.go | 2 +- app/http/endpoints/root/webchatws.go | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/http/endpoints/api/panel/multipanelcreate.go b/app/http/endpoints/api/panel/multipanelcreate.go index a333a80..4605055 100644 --- a/app/http/endpoints/api/panel/multipanelcreate.go +++ b/app/http/endpoints/api/panel/multipanelcreate.go @@ -59,7 +59,7 @@ func MultiPanelCreate(ctx *gin.Context) { // get bot context botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) diff --git a/app/http/endpoints/api/panel/multipanelresend.go b/app/http/endpoints/api/panel/multipanelresend.go index 2907b52..cd362d8 100644 --- a/app/http/endpoints/api/panel/multipanelresend.go +++ b/app/http/endpoints/api/panel/multipanelresend.go @@ -45,7 +45,7 @@ func MultiPanelResend(ctx *gin.Context) { // get bot context botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) return } diff --git a/app/http/endpoints/api/panel/multipanelupdate.go b/app/http/endpoints/api/panel/multipanelupdate.go index 3ccbcd0..76208e3 100644 --- a/app/http/endpoints/api/panel/multipanelupdate.go +++ b/app/http/endpoints/api/panel/multipanelupdate.go @@ -77,7 +77,7 @@ func MultiPanelUpdate(ctx *gin.Context) { // get bot context botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, utils.ErrorJson(err)) + ctx.JSON(500, utils.ErrorJson(err)) return } diff --git a/app/http/endpoints/api/premium.go b/app/http/endpoints/api/premium.go index 4df248b..dae00ba 100644 --- a/app/http/endpoints/api/premium.go +++ b/app/http/endpoints/api/premium.go @@ -14,7 +14,7 @@ func PremiumHandler(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) diff --git a/app/http/endpoints/api/ticket/closeticket.go b/app/http/endpoints/api/ticket/closeticket.go index ba6ca13..1b86a52 100644 --- a/app/http/endpoints/api/ticket/closeticket.go +++ b/app/http/endpoints/api/ticket/closeticket.go @@ -19,7 +19,7 @@ func CloseTicket(ctx *gin.Context) { ticketId, err := strconv.Atoi(ctx.Param("ticketId")) if err != nil { - ctx.AbortWithStatusJSON(400, gin.H{ + ctx.JSON(400, gin.H{ "success": true, "error": "Invalid ticket ID", }) @@ -28,7 +28,7 @@ func CloseTicket(ctx *gin.Context) { var body closeBody if err := ctx.BindJSON(&body); err != nil { - ctx.AbortWithStatusJSON(400, gin.H{ + ctx.JSON(400, gin.H{ "success": false, "error": "Missing reason", }) @@ -38,7 +38,7 @@ func CloseTicket(ctx *gin.Context) { // Get the ticket struct ticket, err := database.Client.Tickets.Get(ticketId, guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": true, "error": err.Error(), }) @@ -47,7 +47,7 @@ func CloseTicket(ctx *gin.Context) { // Verify the ticket exists if ticket.UserId == 0 { - ctx.AbortWithStatusJSON(404, gin.H{ + ctx.JSON(404, gin.H{ "success": false, "error": "Ticket does not exist", }) diff --git a/app/http/endpoints/api/ticket/getticket.go b/app/http/endpoints/api/ticket/getticket.go index 7c6764f..3cc5603 100644 --- a/app/http/endpoints/api/ticket/getticket.go +++ b/app/http/endpoints/api/ticket/getticket.go @@ -21,7 +21,7 @@ func GetTicket(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) @@ -30,7 +30,7 @@ func GetTicket(ctx *gin.Context) { ticketId, err := strconv.Atoi(ctx.Param("ticketId")) if err != nil { - ctx.AbortWithStatusJSON(400, gin.H{ + ctx.JSON(400, gin.H{ "success": true, "error": "Invalid ticket ID", }) @@ -40,7 +40,7 @@ func GetTicket(ctx *gin.Context) { // Get the ticket struct ticket, err := database.Client.Tickets.Get(ticketId, guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": true, "error": err.Error(), }) @@ -48,7 +48,7 @@ func GetTicket(ctx *gin.Context) { } if ticket.GuildId != guildId { - ctx.AbortWithStatusJSON(403, gin.H{ + ctx.JSON(403, gin.H{ "success": false, "error": "Guild ID doesn't match", }) @@ -56,7 +56,7 @@ func GetTicket(ctx *gin.Context) { } if !ticket.Open { - ctx.AbortWithStatusJSON(404, gin.H{ + ctx.JSON(404, gin.H{ "success": false, "error": "Ticket does not exist", }) diff --git a/app/http/endpoints/api/ticket/sendmessage.go b/app/http/endpoints/api/ticket/sendmessage.go index 54846ba..a28471c 100644 --- a/app/http/endpoints/api/ticket/sendmessage.go +++ b/app/http/endpoints/api/ticket/sendmessage.go @@ -25,9 +25,9 @@ func SendMessage(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, - "error": err.Error(), + "error": err.Error(), }) return } @@ -35,7 +35,7 @@ func SendMessage(ctx *gin.Context) { // Get ticket ID ticketId, err := strconv.Atoi(ctx.Param("ticketId")) if err != nil { - ctx.AbortWithStatusJSON(400, gin.H{ + ctx.JSON(400, gin.H{ "success": false, "error": "Invalid ticket ID", }) @@ -44,7 +44,7 @@ func SendMessage(ctx *gin.Context) { var body sendMessageBody if err := ctx.BindJSON(&body); err != nil { - ctx.AbortWithStatusJSON(400, gin.H{ + ctx.JSON(400, gin.H{ "success": false, "error": "Message is missing", }) @@ -54,7 +54,7 @@ func SendMessage(ctx *gin.Context) { if len(body.Message) == 0 { ctx.JSON(400, gin.H{ "success": false, - "error": "You must enter a message", + "error": "You must enter a message", }) return } @@ -67,7 +67,7 @@ func SendMessage(ctx *gin.Context) { } if premiumTier == premium.None { - ctx.AbortWithStatusJSON(402, gin.H{ + ctx.JSON(402, gin.H{ "success": false, "error": "Guild is not premium", }) @@ -79,7 +79,7 @@ func SendMessage(ctx *gin.Context) { // Verify the ticket exists if ticket.UserId == 0 { - ctx.AbortWithStatusJSON(404, gin.H{ + ctx.JSON(404, gin.H{ "success": false, "error": "Ticket not found", }) @@ -88,7 +88,7 @@ func SendMessage(ctx *gin.Context) { // Verify the user has permission to send to this guild if ticket.GuildId != guildId { - ctx.AbortWithStatusJSON(403, gin.H{ + ctx.JSON(403, gin.H{ "success": false, "error": "Guild ID doesn't match", }) @@ -104,7 +104,7 @@ func SendMessage(ctx *gin.Context) { // Preferably send via a webhook webhook, err := database.Client.Webhooks.Get(guildId, ticketId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) @@ -139,7 +139,7 @@ func SendMessage(ctx *gin.Context) { } if ticket.ChannelId == nil { - ctx.AbortWithStatusJSON(404, gin.H{ + ctx.JSON(404, gin.H{ "success": false, "error": "Ticket channel ID is nil", }) @@ -147,7 +147,7 @@ func SendMessage(ctx *gin.Context) { } if _, err = rest.CreateMessage(botContext.Token, botContext.RateLimiter, *ticket.ChannelId, rest.CreateMessageData{Content: body.Message}); err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) diff --git a/app/http/endpoints/api/transcripts/get.go b/app/http/endpoints/api/transcripts/get.go index 5369fd2..52f9223 100644 --- a/app/http/endpoints/api/transcripts/get.go +++ b/app/http/endpoints/api/transcripts/get.go @@ -23,7 +23,7 @@ func GetTranscriptHandler(ctx *gin.Context) { // get ticket object ticket, err := dbclient.Client.Tickets.Get(ticketId, guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) diff --git a/app/http/endpoints/api/transcripts/list.go b/app/http/endpoints/api/transcripts/list.go index 1abdfed..48dffa2 100644 --- a/app/http/endpoints/api/transcripts/list.go +++ b/app/http/endpoints/api/transcripts/list.go @@ -42,7 +42,7 @@ func ListTranscripts(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) diff --git a/app/http/endpoints/api/transcripts/render.go b/app/http/endpoints/api/transcripts/render.go index d6b6a03..3f48c3c 100644 --- a/app/http/endpoints/api/transcripts/render.go +++ b/app/http/endpoints/api/transcripts/render.go @@ -24,7 +24,7 @@ func GetTranscriptRenderHandler(ctx *gin.Context) { // get ticket object ticket, err := dbclient.Client.Tickets.Get(ticketId, guildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), }) diff --git a/app/http/endpoints/root/webchatws.go b/app/http/endpoints/root/webchatws.go index 4a64e71..3cd6780 100644 --- a/app/http/endpoints/root/webchatws.go +++ b/app/http/endpoints/root/webchatws.go @@ -165,7 +165,7 @@ func WebChatWs(ctx *gin.Context) { botContext, err := botcontext.ContextForGuild(authData.GuildId) if err != nil { - ctx.AbortWithStatusJSON(500, gin.H{ + ctx.JSON(500, gin.H{ "success": false, "error": err.Error(), })