Get Api retuning invalid json response

I am having an api method router.GET(“/data/UploadStatus”, func(c *gin.Context). This method will call the db and fetch the values and return the json response.Its working fine as expected but in very rare scenarios, I am getting invalid Json response as its appending “true” value in the response

c.JSON(http.StatusOK, response)

Can you paste some of your codes?

sure…GetUploadStatus will call the sp and get the db values. The JSON response is fine as expected but in very rare scenarios(especially when calling the function concurrently), I am getting invalid Json response as its appending “true” value in the response

if response, err := Data.GetUploadStatus(dbClient, c.Query("byGuid"), c.Query("token")); err == nil {
					c.JSON(http.StatusOK, response)
					if err == nil && len(response.StatusEntry) > 0 {
						entry := response.StatusEntry[0]
						if strings.EqualFold(entry.State, "Complete") {
							LogUploadCompleteStatus(c.Query("account"), c.Query("byGuid"), "Succeeded", entry.StartTime, entry.CompletionTime)
						}
						if strings.EqualFold(entry.State, "Error") {
							LogUploadCompleteStatus(c.Query("account"), c.Query("byGuid"), "Failed", entry.StartTime, entry.CompletionTime)
						}
					}
					if err != nil {
						logger.Debug(c.Query("byGuid"), "Failed to perform uploadStatus"+err.Error())
						c.JSON(http.StatusInternalServerError, err)
					}
				} else {
					logger.Debug(c.Query("byGuid"), "Failed to perform uploadStatus"+err.Error())
					c.JSON(http.StatusInternalServerError, err)
				}

Hi Michael, pls let me know if there is any update…

from you code snippet, sounds logic incorrect , can you change like this :

if response, err := Data.GetUploadStatus(dbClient, c.Query("byGuid"), c.Query("token")); err == nil {
		
		if err == nil && len(response.StatusEntry) > 0 {
			entry := response.StatusEntry[0]
			if strings.EqualFold(entry.State, "Complete") {
				LogUploadCompleteStatus(c.Query("account"), c.Query("byGuid"), "Succeeded", entry.StartTime, entry.CompletionTime)
			}
			if strings.EqualFold(entry.State, "Error") {
				LogUploadCompleteStatus(c.Query("account"), c.Query("byGuid"), "Failed", entry.StartTime, entry.CompletionTime)
			}
		} else {
		c.JSON(http.StatusOK, response)
               }
	} else {
		logger.Debug(c.Query("byGuid"), "Failed to perform uploadStatus"+err.Error())
		c.JSON(http.StatusInternalServerError, err)
	}