From 68a2fb2943c7fc147f38d3e988385aea563ee1b6 Mon Sep 17 00:00:00 2001 From: saopig1 <4x7sw862st@gmail.com> Date: Wed, 27 May 2026 13:31:31 +0800 Subject: [PATCH] refactor(users): use SQLITE_CONSTRAINT_UNIQUE error code instead of message text --- src/data/users.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/data/users.ts b/src/data/users.ts index 8499ccf..d79ca40 100644 --- a/src/data/users.ts +++ b/src/data/users.ts @@ -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;