mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
26 lines
545 B
Go
26 lines
545 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 {
|
|
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
|
|
}
|