Skip to content

Commit

Permalink
Refactored error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mohdjami committed Jan 3, 2025
1 parent dfa7d25 commit 824d1cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 5 additions & 1 deletion app/api/delete-itinerary/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export async function DELETE(req: NextRequest) {
try {
const { id } = await req.json();
const supabase = createClient();
const response = await supabase.from("response").delete().match({ id });
const {data: response, error } = await supabase.from("response").delete().match({ id });
if(error){
console.log(error);
return NextResponse.json({ error: error.message }, { status: 400 });
}
revalidatePath("/");
return NextResponse.json({ message: "Itinerary deleted successfully" });
} catch (error) {
Expand Down
12 changes: 4 additions & 8 deletions app/api/generate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ export async function POST(req: Request, res: Response) {
budget,
interests,
} = await req.json();
const [supabase, user] = await Promise.all([
createClient(),
getServerUser(),
]);
const user = await getServerUser()

if (!user) {

if (!user) {
return NextResponse.json(
{
error: "User not found",
Expand Down Expand Up @@ -102,7 +100,6 @@ export async function POST(req: Request, res: Response) {
.replaceAll("```json", "")
.replaceAll("```", "");
const json = JSON.parse(text);
console.log(json);
const name = `${currentLocation.split(",")[0]} to ${
travelLocation.split(",")[0]
}`;
Expand All @@ -111,7 +108,7 @@ export async function POST(req: Request, res: Response) {
//Insert these details into user preferneces table in supabase
//not critical push them to the queue

const res = await client.publishJSON({
await client.publishJSON({
url: `${process.env.NEXT_PUBLIC_URL}/api/process`,
body: {
currentLocation,
Expand All @@ -125,7 +122,6 @@ export async function POST(req: Request, res: Response) {
json,
},
});
console.log("userid", user.id);
revalidatePath("/");
return NextResponse.json({ itinerary: json });
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
},
"volta": {
"node": "20.18.0"
}
}

0 comments on commit 824d1cc

Please sign in to comment.