refactor(users): use SQLITE_CONSTRAINT_UNIQUE error code instead of message text

This commit is contained in:
saopig1 committed 2026-05-27 13:31:31 +08:00
1 parent 34523cb00f
commit 68a2fb2943
1 file changed
+1 -2
+1 -2
View File
@@ -55,8 +55,7 @@ export function createUserStore(db: Database.Database): UserStore {
try { try {
insertStmt.run(id, username, hash, now, now); insertStmt.run(id, username, hash, now, now);
} catch (err) { } catch (err) {
const msg = (err as Error).message; if (err && typeof err === "object" && (err as { code?: string }).code === "SQLITE_CONSTRAINT_UNIQUE") {
if (msg.includes("UNIQUE") && msg.includes("users.username")) {
throw new UsernameTakenError(username); throw new UsernameTakenError(username);
} }
throw err; throw err;