VILLASweb-backend-go/common/dberrorhandling.go
2019-05-16 16:58:53 +02:00

24 lines
463 B
Go

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 {
c.JSON(http.StatusNotFound, gin.H{
"error": "No files found in DB",
})
} else {
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Error on DB Query or transaction",
})
}
return true // Error
}
return false // No error
}