Files
spend-sparrow/db/error.go
Tim Wundenberg dbf272e3f3
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m49s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m29s
feat(transaction): #66 implement transactions
2025-05-16 11:06:48 +02:00

39 lines
660 B
Go

package db
import (
"database/sql"
"errors"
"spend-sparrow/log"
"spend-sparrow/types"
)
var (
ErrNotFound = errors.New("the value does not exist")
ErrAlreadyExists = errors.New("row already exists")
)
func TransformAndLogDbError(module string, r sql.Result, err error) error {
if err != nil {
if err == sql.ErrNoRows {
return ErrNotFound
}
log.Error("%v: %v", module, err)
return types.ErrInternal
}
if r != nil {
rows, err := r.RowsAffected()
if err != nil {
log.Error("%v: %v", module, err)
return types.ErrInternal
}
if rows == 0 {
log.Info("%v: not found", module)
return ErrNotFound
}
}
return nil
}