diff --git a/src/lib/db/databaseUtils.server.ts b/src/lib/db/databaseUtils.server.ts index f84ed1ed..fb1e94e9 100644 --- a/src/lib/db/databaseUtils.server.ts +++ b/src/lib/db/databaseUtils.server.ts @@ -114,7 +114,16 @@ export const getExistingGuest = async (username: string, meeting: MeetingSelectS * @returns The id of the inserted meeting. */ export const insertMeeting = async (meeting: MeetingInsertSchema, meetingDates: Date[]) => { - const [dbMeeting] = await db.insert(meetings).values(meeting).returning(); + let dbMeeting: MeetingSelectSchema; + + try { + [dbMeeting] = await db.insert(meetings).values(meeting).returning(); + } catch (err) { + const meetingSerialized = JSON.stringify(meeting); + console.error("Error inserting meeting=", meetingSerialized); + throw Error(`Error inserting meeting=${meetingSerialized}`); + } + await insertMeetingDates(meetingDates, dbMeeting.id); return dbMeeting.id; }; @@ -132,7 +141,12 @@ export const insertMeetingDates = async (dates: Date[], meeting_id: string) => { return { meeting_id, date: startOfDay }; }); - await db.insert(meetingDates).values(dbMeetingDates); + try { + await db.insert(meetingDates).values(dbMeetingDates); + } catch (err) { + console.error("Error inserting meeting dates=", dbMeetingDates); + throw Error(`Error inserting meeting dates=${dbMeetingDates}`); + } }; export const getExistingMeetingDates = async (meetingId: string) => { diff --git a/src/routes/api/create/+server.ts b/src/routes/api/create/+server.ts index 2aceb842..8978d918 100644 --- a/src/routes/api/create/+server.ts +++ b/src/routes/api/create/+server.ts @@ -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 @@ -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, meeting, sortedDates); + // TODO: This is unsafe + throw error(500, `Error creating meeting: ${err.message}`); } } diff --git a/sst.config.ts b/sst.config.ts index bfe69e7f..265b5762 100644 --- a/sst.config.ts +++ b/sst.config.ts @@ -19,7 +19,6 @@ export default { domainName: `${stack.stage === "prod" ? "" : `${stack.stage}.`}zotmeet.com`, hostedZone: "zotmeet.com", cdk: { - // @ts-expect-error Constructs types are broken, see https://github.com/sst/sst/issues/3483 certificate: Certificate.fromCertificateArn( stack, "MyCert", @@ -30,5 +29,15 @@ export default { }); stack.addOutputs({ url: site.url }); }); + + // Reference: https://docs.sst.dev/advanced/source-maps + app.setDefaultFunctionProps({ + environment: { + NODE_OPTIONS: "--enable-source-maps", + }, + nodejs: { + sourcemap: true, + }, + }); }, } satisfies SSTConfig;