Replace string-matching error detection with typed SQLite errors
All checks were successful
check / check (push) Successful in 2m17s
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user