From 388dfcbbab1b18b381158a1e8679bcf8f175623b Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 27 Dec 2023 13:50:38 +0700 Subject: [PATCH] fix api response codes if user is nil --- echo_handlers.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/echo_handlers.go b/echo_handlers.go index 997a7ffc..127734ae 100644 --- a/echo_handlers.go +++ b/echo_handlers.go @@ -151,11 +151,7 @@ func (svc *Service) AppsShowHandler(c echo.Context) error { }) } if user == nil { - return c.JSON(http.StatusBadRequest, ErrorResponse{ - Error: true, - Code: 8, - Message: "User does not exist", - }) + return c.NoContent(http.StatusUnauthorized) } app := App{} @@ -236,11 +232,7 @@ func (svc *Service) AppsCreateHandler(c echo.Context) error { }) } if user == nil { - return c.JSON(http.StatusBadRequest, ErrorResponse{ - Error: true, - Code: 8, - Message: "User does not exist", - }) + return c.NoContent(http.StatusUnauthorized) } name := c.FormValue("name") @@ -367,16 +359,12 @@ func (svc *Service) AppsDeleteHandler(c echo.Context) error { return err } if user == nil { - return c.JSON(http.StatusBadRequest, ErrorResponse{ - Error: true, - Code: 8, - Message: "User does not exist", - }) + return c.NoContent(http.StatusUnauthorized) } app := App{} svc.db.Where("user_id = ? AND nostr_pubkey = ?", user.ID, c.Param("pubkey")).First(&app) svc.db.Delete(&app) - return c.JSON(http.StatusOK, "App deleted successfully") + return c.NoContent(http.StatusNoContent) } func (svc *Service) LogoutHandler(c echo.Context) error {