From dbc512237a24b0493d21b82da3c39b009d98d9e3 Mon Sep 17 00:00:00 2001 From: rxdn <29165304+rxdn@users.noreply.github.com> Date: Sun, 10 Sep 2023 18:08:36 +0100 Subject: [PATCH] Handle non-existent channel --- app/http/endpoints/api/panel/panelupdate.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/http/endpoints/api/panel/panelupdate.go b/app/http/endpoints/api/panel/panelupdate.go index fc9aa27..8214ec9 100644 --- a/app/http/endpoints/api/panel/panelupdate.go +++ b/app/http/endpoints/api/panel/panelupdate.go @@ -148,14 +148,20 @@ func UpdatePanel(ctx *gin.Context) { newMessageId, err = messageData.send(&botContext) if err != nil { var unwrapped request.RestError - if errors.As(err, &unwrapped) && unwrapped.StatusCode == 403 { - ctx.JSON(500, utils.ErrorStr("I do not have permission to send messages in the specified channel")) + if errors.As(err, &unwrapped) { + if unwrapped.StatusCode == 403 { + ctx.JSON(403, utils.ErrorStr("I do not have permission to send messages in the specified channel")) + return + } else if unwrapped.StatusCode == 404 { + // Swallow error + // TODO: Make channel_id column nullable, and set to null + } else { + ctx.JSON(500, utils.ErrorJson(err)) + } } else { - // TODO: Most appropriate error? ctx.JSON(500, utils.ErrorJson(err)) + return } - - return } }