TP-5555 | handle incorrect payload

This commit is contained in:
varnit goyal
2024-12-11 16:03:07 +05:30
parent ac1df0c010
commit 426f523cbc

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