forked from ebhomengo/niki
fix error handling defer close in repo layer
This commit is contained in:
parent
6853ddaf64
commit
85b9a7254e
|
@ -4,9 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
"git.gocasts.ir/ebhomengo/niki/logger"
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||
)
|
||||
|
@ -29,13 +27,16 @@ func (d DB) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (en
|
|||
return kindBoxReq, nil
|
||||
}
|
||||
|
||||
func (d DB) AcceptKindBoxReq(ctx context.Context, kindBoxReqID, countAccepted uint) error {
|
||||
func (d DB) AcceptKindBoxReq(ctx context.Context, kindBoxReqID, countAccepted uint) (finalErr error) {
|
||||
op := richerror.Op("mysqlkindboxreq.AcceptKindBoxReq")
|
||||
statement, err := d.conn.Conn().
|
||||
Prepare(`update kind_box_reqs set count_accepted = ? , status = ? where id = ?`)
|
||||
|
||||
defer func() {
|
||||
dErr := statement.Close()
|
||||
logger.L().Error(dErr.Error())
|
||||
cErr := statement.Close()
|
||||
if cErr != nil {
|
||||
finalErr = cErr
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
|
@ -79,13 +80,15 @@ func (d DB) KindBoxRequestExist(id uint) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (d DB) RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error {
|
||||
func (d DB) RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) (finalErr error) {
|
||||
op := richerror.Op("mysqlkindboxreq.RejectKindBoxReq")
|
||||
statement, err := d.conn.Conn().
|
||||
Prepare(`update kind_box_reqs set description = ? , status = ? where id = ?`)
|
||||
defer func() {
|
||||
dErr := statement.Close()
|
||||
logger.L().Error(dErr.Error())
|
||||
cErr := statement.Close()
|
||||
if cErr != nil {
|
||||
finalErr = cErr
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err).
|
||||
|
@ -100,13 +103,15 @@ func (d DB) RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d DB) RollbackKindBoxRequestStatus(ctx context.Context, id uint) error {
|
||||
func (d DB) RollbackKindBoxRequestStatus(ctx context.Context, id uint) (finalErr error) {
|
||||
op := richerror.Op("mysqlkindboxreq.RollbackKindBoxRequestStatus")
|
||||
statement, err := d.conn.Conn().
|
||||
Prepare(`update kind_box_reqs set status = ? where id = ?`)
|
||||
defer func() {
|
||||
dErr := statement.Close()
|
||||
logger.L().Error(dErr.Error())
|
||||
cErr := statement.Close()
|
||||
if cErr != nil {
|
||||
finalErr = cErr
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err).
|
||||
|
|
Loading…
Reference in New Issue