Replace string-matching error detection with typed SQLite errors
All checks were successful
check / check (push) Successful in 2m17s

Use errors.As with *sqlite.Error and SQLITE_CONSTRAINT_UNIQUE code
instead of fragile strings.Contains(err.Error(), "UNIQUE") checks.

Add db.IsUniqueConstraintError helper in internal/db/errors.go and
replace all three string-matching call sites in api.go and auth.go.
This commit is contained in:
user
2026-03-10 03:18:33 -07:00
parent f287fdf6d1
commit 25cbbfd42a
3 changed files with 26 additions and 3 deletions

View File

@@ -4,6 +4,8 @@ import (
"encoding/json"
"net/http"
"strings"
"git.eeqj.de/sneak/neoirc/internal/db"
)
const minPasswordLength = 8
@@ -94,7 +96,7 @@ func (hdlr *Handlers) handleRegisterError(
request *http.Request,
err error,
) {
if strings.Contains(err.Error(), "UNIQUE") {
if db.IsUniqueConstraintError(err) {
hdlr.respondError(
writer, request,
"nick already taken",