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:
@@ -3,7 +3,7 @@ import { eq, and, sql } from "drizzle-orm";
|
||||
import { config } from "@shared/lib/config";
|
||||
import { withTransaction } from "@/lib/db";
|
||||
import type { Transaction } from "@shared/lib/types";
|
||||
import { UserError } from "@shared/lib/errors";
|
||||
import { UserError, SystemError } from "@shared/lib/errors";
|
||||
import { TimerType, TransactionType } from "@shared/lib/constants";
|
||||
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||
|
||||
@@ -94,13 +94,13 @@ class TriviaService {
|
||||
const data = await response.json() as OpenTDBResponse;
|
||||
|
||||
if (data.response_code !== 0 || !data.results || data.results.length === 0) {
|
||||
throw new Error('Failed to fetch trivia question');
|
||||
throw new SystemError('Failed to fetch trivia question');
|
||||
}
|
||||
|
||||
const result = data.results[0];
|
||||
|
||||
if (!result) {
|
||||
throw new Error('No trivia question returned');
|
||||
throw new SystemError('No trivia question returned');
|
||||
}
|
||||
|
||||
// Decode base64
|
||||
|
||||
Reference in New Issue
Block a user