From 426f523cbc423f30bae4b6ee2d1dc51bd1b67c53 Mon Sep 17 00:00:00 2001 From: varnit goyal Date: Wed, 11 Dec 2024 16:03:07 +0530 Subject: [PATCH] TP-5555 | handle incorrect payload --- service/ExceptionService.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/ExceptionService.go b/service/ExceptionService.go index 3d8a484..68f2f4d 100644 --- a/service/ExceptionService.go +++ b/service/ExceptionService.go @@ -15,6 +15,7 @@ import ( "encoding/json" "fmt" "github.com/gin-gonic/gin" + "go.uber.org/zap" "gorm.io/gorm" "net/http" ) @@ -117,6 +118,11 @@ func (exceptionService *ExceptionService) CatchErrors(c *gin.Context) { var jsonData Payload + //ensure we are processing a valid payload + if len(lines) <= 2 { + exceptionService.logger.Error("payload is not valid", zap.Strings("payload", lines)) + c.JSON(http.StatusOK, gin.H{"status": "payload is not valid"}) + } err := json.Unmarshal([]byte(lines[2]), &jsonData) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "Second line is not valid JSON"})