package common import ( "net/http" "github.com/gin-gonic/gin" "github.com/jinzhu/gorm" ) func ProvideErrorResponse(c *gin.Context, err error) bool { if err != nil { if err == gorm.ErrRecordNotFound { errormsg := "Record not Found in DB: " + err.Error() c.JSON(http.StatusNotFound, gin.H{ "error": errormsg, }) } else { errormsg := "Error on DB Query or transaction: " + err.Error() c.JSON(http.StatusInternalServerError, gin.H{ "error": errormsg, }) } return true // Error } return false // No error }