Files
spend-sparrow/db/error.go
Tim Wundenberg 128a2fc4d7
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m22s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m26s
fix: lint errors
2025-05-26 08:39:32 +02:00

39 lines
669 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 errors.Is(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
}