Skip to content

Commit

Permalink
Update error handling in api route
Browse files Browse the repository at this point in the history
  • Loading branch information
salimi-my committed Feb 4, 2024
1 parent 9706aac commit a74aa24
Show file tree
Hide file tree
Showing 20 changed files with 246 additions and 48 deletions.
13 changes: 11 additions & 2 deletions app/api/about/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,19 @@ export async function POST(req: Request) {

return NextResponse.json({ success: true, about });
}
} catch (error: any) {
} catch (error) {
console.log('[ABOUT_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/account/password/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,19 @@ export async function POST(req: Request) {
});

return NextResponse.json({ success: true, user: updatedUser });
} catch (error: any) {
} catch (error) {
console.log('[PASSWORD_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/account/profile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ export async function POST(req: Request) {
});

return NextResponse.json({ success: true, user: updatedUser });
} catch (error: any) {
} catch (error) {
console.log('[PROFILE_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/experience/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true, experiences });
} catch (error: any) {
} catch (error) {
console.log('[EXPERIENCE_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/expertise/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true, expertises });
} catch (error: any) {
} catch (error) {
console.log('[EXPERTISE_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/miscellaneous/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,19 @@ export async function POST(req: Request) {

return NextResponse.json({ success: true, miscellaneous, titlesCreated });
}
} catch (error: any) {
} catch (error) {
console.log('[MISCELLANEOUS_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
26 changes: 22 additions & 4 deletions app/api/portfolio/[portfolioId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,19 @@ export async function PATCH(
revalidatePath('/');

return NextResponse.json({ success: true, portfolio, tagsCreated });
} catch (error: any) {
} catch (error) {
console.log('[PORTFOLIO_PATCH]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down Expand Up @@ -173,10 +182,19 @@ export async function DELETE(
revalidatePath('/');

return NextResponse.json({ success: true, portfolio });
} catch (error: any) {
} catch (error) {
console.log('[PORTFOLIO_DELETE]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/portfolio/delete-multiple/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true });
} catch (error: any) {
} catch (error) {
console.log('[PORTFOLIO_DELETE_MULTIPLE_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
26 changes: 22 additions & 4 deletions app/api/portfolio/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true, portfolio, tagsCreated });
} catch (error: any) {
} catch (error) {
console.log('[PORTFOLIO_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand All @@ -119,10 +128,19 @@ export async function GET(req: NextRequest) {
const photosWithBlur = await addBlurredDataUrls(portfolios);

return NextResponse.json(photosWithBlur);
} catch (error: any) {
} catch (error) {
console.log('[PORTFOLIO_GET]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
26 changes: 22 additions & 4 deletions app/api/qualification/[qualificationId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,19 @@ export async function PATCH(
revalidatePath('/');

return NextResponse.json({ success: true, qualification });
} catch (error: any) {
} catch (error) {
console.log('[QUALIFICATION_PATCH]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down Expand Up @@ -161,10 +170,19 @@ export async function DELETE(
revalidatePath('/');

return NextResponse.json({ success: true, qualification });
} catch (error: any) {
} catch (error) {
console.log('[QUALIFICATION_DELETE]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/qualification/delete-multiple/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true });
} catch (error: any) {
} catch (error) {
console.log('[QUALIFICATION_DELETE_MULTIPLE_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/qualification/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true, qualification });
} catch (error: any) {
} catch (error) {
console.log('[QUALIFICATION_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
13 changes: 11 additions & 2 deletions app/api/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ export async function POST(req: Request) {
revalidatePath('/');

return NextResponse.json({ success: true, user });
} catch (error: any) {
} catch (error) {
console.log('[REGISTER_POST]', error);

let message;

if (error instanceof Error) {
message = error.message;
} else {
message = String(error);
}

return NextResponse.json(
{ success: false, error: error.message },
{ success: false, error: message },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/resume/download-file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export async function POST(req: Request) {

return new Response(pdfData, { headers });
} catch (error) {
console.log('[DOWNLOAD_FILE_POST]', error);

let message;

if (error instanceof Error) {
Expand All @@ -65,8 +67,6 @@ export async function POST(req: Request) {
message = String(error);
}

console.log('[DOWNLOAD_FILE_POST]', error);

return NextResponse.json(
{ success: false, error: message },
{ status: 500 }
Expand Down
4 changes: 2 additions & 2 deletions app/api/resume/generate-link/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export async function POST(req: Request) {

return NextResponse.json({ success: true, data });
} catch (error) {
console.log('[GENERATE_LINK_POST]', error);

let message;

if (error instanceof Error) {
Expand All @@ -61,8 +63,6 @@ export async function POST(req: Request) {
message = String(error);
}

console.log('[GENERATE_LINK_POST]', error);

return NextResponse.json(
{ success: false, error: message },
{ status: 500 }
Expand Down
Loading

0 comments on commit a74aa24

Please sign in to comment.