diff --git a/payment/api/goods.go b/payment/api/goods.go index 99f5e4c8..bf85dd7f 100644 --- a/payment/api/goods.go +++ b/payment/api/goods.go @@ -14,7 +14,7 @@ func (api *API) GetGoods(c *gin.Context) { goods, err := api.Database.GetGoods() if err != nil { log.WithError(err).Error("cannot get goods") - c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, "cannot get goods: "+err.Error()) return } c.JSON(http.StatusOK, goods) @@ -43,7 +43,7 @@ func (api *API) AddGood(c *gin.Context) { c.JSON(http.StatusConflict, "good already exists") } else { logger.WithError(err).Error("cannot insert body in database") - c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, "cannot insert body in database: "+err.Error()) } return } diff --git a/payment/api/idpay.go b/payment/api/idpay.go index 96560056..59432d08 100644 --- a/payment/api/idpay.go +++ b/payment/api/idpay.go @@ -35,7 +35,7 @@ func (api *API) CreateTransaction(c *gin.Context) { c.JSON(http.StatusBadRequest, err.Error()) } else { logger.WithError(err).Error("cannot query goods") - c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, "cannot query goods: "+err.Error()) } return } @@ -50,7 +50,7 @@ func (api *API) CreateTransaction(c *gin.Context) { err = api.Database.InitiateTransaction(&payment) if err != nil { logger.WithError(err).Error("cannot put the transaction in database") - c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, "cannot put the transaction in database: "+err.Error()) return } // Initiate the request in idpay @@ -65,7 +65,7 @@ func (api *API) CreateTransaction(c *gin.Context) { }) if err != nil { logger.WithError(err).Error("cannot start idpay transaction") - c.JSON(http.StatusInternalServerError, err.Error()) + c.JSON(http.StatusInternalServerError, "cannot start idpay transaction: "+err.Error()) // Mark the transaction in database as failed api.Database.MarkAsFailed(payment.OrderID) return diff --git a/payment/internal/database/payment.go b/payment/internal/database/payment.go index 0ebe17a4..74737cd8 100644 --- a/payment/internal/database/payment.go +++ b/payment/internal/database/payment.go @@ -19,7 +19,7 @@ func (db PaymentDatabase) GetGoodsFromName(names []string) ([]Good, error) { // TODO: There SHOULD be a better way result := make([]Good, len(names)) for i, name := range names { - if err := db.db.Where("name = ?", name).Find(&result[i]).Error; err != nil { + if err := db.db.Where("name = ?", name).First(&result[i]).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return nil, GoodNotFoundError{GoodName: name} } else {