mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
refactor(users): use SQLITE_CONSTRAINT_UNIQUE error code instead of message text
This commit is contained in:
1 parent
34523cb00f
commit
68a2fb2943
1 file changed
+1
-2
+1
-2
@@ -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;
|
||||||
|
|||||||
Reference in new issue
Block a user