fix: standardize error classes in shared service modules
Replace raw `Error` with `UserError` for user-facing conditions (invalid trade state, user not found, permission/channel type checks) and `SystemError` for internal failures (DB insert failures, external API errors, missing config). Improves Discord UX by ensuring user-facing errors are surfaced cleanly via withCommandErrorHandling. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { withTransaction } from "@/lib/db";
|
||||
import { config } from "@shared/lib/config";
|
||||
import type { Transaction } from "@shared/lib/types";
|
||||
import { TimerKey, TimerType } from "@shared/lib/constants";
|
||||
import { UserError } from "@shared/lib/errors";
|
||||
|
||||
export const levelingService = {
|
||||
// Calculate total XP required to REACH a specific level (Cumulative)
|
||||
@@ -49,7 +50,7 @@ export const levelingService = {
|
||||
where: eq(users.id, BigInt(id)),
|
||||
});
|
||||
|
||||
if (!user) throw new Error("User not found");
|
||||
if (!user) throw new UserError("User not found");
|
||||
|
||||
const currentXp = user.xp ?? 0n;
|
||||
const newXp = currentXp + amount;
|
||||
|
||||
Reference in New Issue
Block a user