diff --git a/src/app/api/upload/csv/route.ts b/src/app/api/upload/csv/route.ts index 8bb3a09b..f26e9185 100644 --- a/src/app/api/upload/csv/route.ts +++ b/src/app/api/upload/csv/route.ts @@ -1,4 +1,3 @@ -import { user } from "@/app/db/schema/users"; import S3 from "aws-sdk/clients/s3"; import { NextRequest, NextResponse } from "next/server"; import { z } from "zod"; @@ -18,11 +17,18 @@ export async function GET(request: NextRequest) { // For the moment, this api specifically handles uploads of csvs const body = await request.json(); + let validatedBody; try { - const validatedBody = PresignedUrlBodySchema.parse(body); - const { userId, portfolioId } = validatedBody; + validatedBody = PresignedUrlBodySchema.parse(body); + } catch (error) { + console.error("Invalid input: ", error); + return new NextResponse(JSON.stringify({ msg: "Invalid input" }), { + status: 400, + }); + } + try { const s3 = new S3({ signatureVersion: "v4", region: process.env.PRESIGN_AWS_REGION, @@ -30,6 +36,7 @@ export async function GET(request: NextRequest) { secretAccessKey: process.env.PRESIGN_AWS_SECRET_KEY, }); + const { userId, portfolioId } = validatedBody; const fileKey = generateS3Key( userId, portfolioId, @@ -49,6 +56,8 @@ export async function GET(request: NextRequest) { }); } catch (error) { console.error(error); - throw error; + return new NextResponse(JSON.stringify({ msg: "Insternal server error" }), { + status: 500, + }); } }