fix: improve error handling and type safety

- Replaced 'any' types with proper TypeScript types
- Improved error handling with instanceof checks
- Removed unused imports (calculateExpectedTeamScore)
- Updated error messages to be more descriptive
- Removed deprecated eslint.config.mjs file
This commit is contained in:
2026-03-29 21:20:40 -07:00
parent 576dfda619
commit c9415d490e
11 changed files with 30 additions and 54 deletions
+3 -2
View File
@@ -150,8 +150,9 @@ export default function NewTournamentPage() {
// Redirect to game entry page
router.push(`/admin/tournaments/${tournamentId}/entry`)
} catch (err: any) {
setError(err.message)
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "An unexpected error occurred";
setError(message)
} finally {
setIsLoading(false)
}
+9 -7
View File
@@ -3,7 +3,7 @@ import { prisma } from "@/lib/prisma";
import Papa from "papaparse";
import { canManageTournament } from "@/lib/permissions";
import { getSession } from "@/lib/auth-simple";
import { calculateTeamElo, calculateExpectedTeamScore, calculateTeamEloChange } from "@/lib/elo-utils";
import { calculateTeamElo, calculateTeamEloChange } from "@/lib/elo-utils";
interface CSVRow {
"Event #": string;
@@ -62,7 +62,7 @@ export async function POST(request: Request) {
if (parseResult.errors.length > 0) {
return NextResponse.json(
{ error: "CSV parsing errors", errors: parseResult.errors.map((e: any) => e.message) },
{ error: "CSV parsing errors", errors: parseResult.errors.map((e: { message: string }) => e.message) },
{ status: 400 }
);
}
@@ -164,15 +164,16 @@ export async function POST(request: Request) {
registrationDate: new Date(),
},
});
} catch (error) {
} catch {
// Participant already exists, which is fine
console.log(`Participant ${player.id} already exists in tournament ${eventId}`);
}
}
importedCount++;
} catch (err: any) {
errors.push(`Row ${index + 2}: ${err.message}`);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Unknown error";
errors.push(`Row ${index + 2}: ${message}`);
errorCount++;
}
}
@@ -182,10 +183,11 @@ export async function POST(request: Request) {
errorCount,
errors: errors.length > 0 ? errors : undefined,
});
} catch (error: any) {
} catch (error: unknown) {
console.error("Upload error:", error);
const message = error instanceof Error ? error.message : "Failed to upload CSV";
return NextResponse.json(
{ error: error.message || "Failed to upload CSV" },
{ error: message },
{ status: 500 }
);
}
@@ -4,18 +4,7 @@ import { canManageTournament } from "@/lib/permissions";
import { getSession } from "@/lib/auth-simple";
import { calculateTeamElo, calculateTeamEloChange } from "@/lib/elo-utils";
interface GameEntry {
round: number
table: string
player1: string
player2: string
score1: number
player3: string
player4: string
score2: number
}
const K_FACTOR = 32;
const K_FACTOR = 32; // Standard K-factor for Elo calculations
export async function POST(
request: Request,
@@ -139,15 +128,16 @@ export async function POST(
},
});
}
} catch (error) {
} catch {
// Participant already exists, which is fine
console.log(`Participant ${player.id} already exists in tournament ${tournamentId}`);
}
}
importedCount++;
} catch (err: any) {
errors.push(`Game ${index + 1}: ${err.message}`);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "Unknown error";
errors.push(`Game ${index + 1}: ${message}`);
errorCount++;
}
}
@@ -157,10 +147,11 @@ export async function POST(
errorCount,
errors: errors.length > 0 ? errors : undefined,
});
} catch (error: any) {
} catch (error: unknown) {
console.error("Bulk game submission error:", error);
const message = error instanceof Error ? error.message : "Failed to submit games";
return NextResponse.json(
{ error: error.message || "Failed to submit games" },
{ error: message },
{ status: 500 }
);
}
+1 -1
View File
@@ -39,7 +39,7 @@ export async function GET(
}
return NextResponse.json({ role: user.role });
} catch (error) {
} catch {
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ export default function LoginPage() {
// Navigate to admin page - Better Auth will handle session update
router.push("/admin")
}
} catch (err) {
} catch {
setError("An unexpected error occurred")
} finally {
setLoading(false)