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 {
insertStmt.run(id, username, hash, now, now);
} catch (err) {
const msg = (err as Error).message;
if (msg.includes("UNIQUE") && msg.includes("users.username")) {
if (err && typeof err === "object" && (err as { code?: string }).code === "SQLITE_CONSTRAINT_UNIQUE") {
throw new UsernameTakenError(username);
}
throw err;