Skip to content

Commit

Permalink
feat: ✨ throw sveltekit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhxNguyen7 committed Jun 3, 2024
1 parent a1db1c3 commit 634c646
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/routes/api/create/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export async function POST({ request }) {
console.log("Creating meeting:", title, description, fromTime, toTime, meetingDates);

if (fromTime >= toTime) {
error(400, "From time must be before to time");
throw error(400, "From time must be before to time");
}

if (meetingDates.length === 0) {
error(400, "At least one date must be provided");
throw error(400, "At least one date must be provided");
}

// Just so we don't get flooded too easily
if (meetingDates.length > 100) {
error(400, "Too many dates provided");
throw error(400, "Too many dates provided");
}

const sortedDates = meetingDates
Expand All @@ -41,7 +41,8 @@ export async function POST({ request }) {
const meetingId = await insertMeeting(meeting, sortedDates);
return json({ meetingId });
} catch (err) {
console.log("Error creating meeting:", err);
error(500, "Error creating meeting");
console.error("Error creating meeting:", err.message);
// TODO: This is unsafe
throw error(500, `Error creating meeting: ${err.message}`);
}
}

0 comments on commit 634c646

Please sign in to comment.