Merge pull request #57 from navi-ppl/TP-5555/hotfix-wrong-payload

TP-5555 | handle incorrect payload
This commit is contained in:
Varnit Goyal
2024-12-11 16:04:06 +05:30
committed by GitHub

View File

@@ -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"})