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:
@@ -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 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user