This commit is contained in:
jdl
2026-06-13 14:46:55 +02:00
parent 3dcd1c1080
commit 76fce15e32
2 changed files with 90 additions and 0 deletions

33
hub/errs/db.go Normal file
View File

@@ -0,0 +1,33 @@
package errs
import (
"database/sql"
"errors"
"log"
sqlite3 "github.com/mattn/go-sqlite3"
)
func DB(err error) error {
if err == nil {
return nil
}
if _, ok := err.(*Error); ok {
return err
}
if err == sql.ErrNoRows {
return ErrNotFound
}
var se sqlite3.Error
if errors.As(err, &se) {
switch se.ExtendedCode {
case sqlite3.ErrConstraintUnique, sqlite3.ErrConstraintPrimaryKey:
return ErrAlreadyExists
}
}
log.Printf("Unexpected error: %v", err)
return ErrUnexpected
}