TP-5555 | handle incorrect payload
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"go.uber.org/zap"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -117,6 +118,11 @@ func (exceptionService *ExceptionService) CatchErrors(c *gin.Context) {
|
|||||||
|
|
||||||
var jsonData Payload
|
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)
|
err := json.Unmarshal([]byte(lines[2]), &jsonData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Second line is not valid JSON"})
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Second line is not valid JSON"})
|
||||||
|
|||||||
Reference in New Issue
Block a user