Skip to content

Commit

Permalink
removing handle errors raw from the Daily video client
Browse files Browse the repository at this point in the history
  • Loading branch information
Lola-Ojabowale committed Sep 17, 2021
1 parent 5f9139f commit ac2dff3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
12 changes: 2 additions & 10 deletions lib/dailyVideoClient.ts
Expand Up @@ -32,14 +32,6 @@ function handleErrorsJson(response) {
return response.json();
}

function handleErrorsRaw(response) {
if (!response.ok) {
response.text().then(console.log);
throw Error(response.statusText);
}
return response.text();
}

const dailyCredential = process.env.DAILY_API_KEY;

interface DailyVideoApiAdapter {
Expand Down Expand Up @@ -91,7 +83,7 @@ const DailyVideo = (credential): DailyVideoApiAdapter => {
headers: {
Authorization: "Bearer " + dailyCredential,
},
}).then(handleErrorsRaw),
}).then(handleErrorsJson),
dailyUpdateMeeting: (uid: string, event: CalendarEvent) =>
fetch("https://api.daily.co/v1/rooms/" + uid, {
method: "POST",
Expand All @@ -100,7 +92,7 @@ const DailyVideo = (credential): DailyVideoApiAdapter => {
"Content-Type": "application/json",
},
body: JSON.stringify(translateEvent(event)),
}).then(handleErrorsRaw),
}).then(handleErrorsJson),
};
};

Expand Down
7 changes: 4 additions & 3 deletions pages/api/cancel.ts
Expand Up @@ -26,6 +26,7 @@ export default async function handler(req, res) {
},
},
attendees: true,
location: true,
references: {
select: {
uid: true,
Expand All @@ -52,17 +53,16 @@ export default async function handler(req, res) {

const apiDeletes = async.mapLimit(bookingToDelete.user.credentials, 5, async (credential) => {
const bookingRefUid = bookingToDelete.references.filter((ref) => ref.type === credential.type)[0]?.uid;

if (bookingRefUid) {
if (credential.type.endsWith("_calendar")) {
return await deleteEvent(credential, bookingRefUid);
} else if (credential.type.endsWith("_video")) {
return await deleteMeeting(credential, bookingRefUid);
}
}

//deleting a Daily meeting
const isDaily = bookingToDelete.references.filter((ref) => ref.type === "daily");

const isDaily = bookingToDelete.location === "integrations:daily";
const bookingUID = bookingToDelete.references.filter((ref) => ref.type === "daily")[0]?.uid;
if (isDaily) {
return await dailyDeleteMeeting(credential, bookingUID);
Expand All @@ -74,6 +74,7 @@ export default async function handler(req, res) {
bookingId: bookingToDelete.id,
},
});

const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
where: {
bookingId: bookingToDelete.id,
Expand Down
12 changes: 3 additions & 9 deletions pages/call/[uid].tsx
Expand Up @@ -2,7 +2,6 @@ import { useEffect } from "react";
import DailyIframe from "@daily-co/daily-js";
import prisma from "../../lib/prisma";
import { getSession } from "next-auth/client";
import type { NextApiRequest } from "next";
import { useRouter } from "next/router";

export default function JoinCall(props, session) {
Expand Down Expand Up @@ -79,17 +78,12 @@ export async function getServerSideProps(context) {
},
});

const session = await getSession();

return {
props: {
booking: booking,
session: session,
},
};
}

export async function handler(req: NextApiRequest) {
const session = await getSession({ req: req });

if (session) {
return session;
}
}

0 comments on commit ac2dff3

Please sign in to comment.