From 276575daddc274b005ecb916ef0ff211ea6ff94d Mon Sep 17 00:00:00 2001 From: oiov Date: Wed, 30 Oct 2024 15:36:27 +0800 Subject: [PATCH] fixup error info --- app/(protected)/dashboard/scrape/meta-scraping.tsx | 5 +++-- app/api/scraping/meta/route.ts | 11 ++++++----- app/api/scraping/screenshot/route.ts | 11 ++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/(protected)/dashboard/scrape/meta-scraping.tsx b/app/(protected)/dashboard/scrape/meta-scraping.tsx index af897b7..50a4eb6 100644 --- a/app/(protected)/dashboard/scrape/meta-scraping.tsx +++ b/app/(protected)/dashboard/scrape/meta-scraping.tsx @@ -74,7 +74,7 @@ export default function MetaScraping({ `/api/scraping/meta?url=${protocol}${currentLink}&key=${user.apiKey}`, ); if (!res.ok || res.status !== 200) { - toast.error(res.statusText || "Error"); + toast.error(res.statusText || "Something went wrong"); } else { const data = await res.json(); setMetaInfo(data); @@ -90,7 +90,8 @@ export default function MetaScraping({ const payload = `/api/scraping/screenshot?url=${protocol}${currentScreenshotLink}&key=${user.apiKey}`; const res = await fetch(payload); if (!res.ok || res.status !== 200) { - toast.error(res.statusText); + console.log(res); + toast.error(res.statusText || "Something went wrong"); } else { const blob = await res.blob(); const imageUrl = URL.createObjectURL(blob); diff --git a/app/api/scraping/meta/route.ts b/app/api/scraping/meta/route.ts index 57a428d..06f9370 100644 --- a/app/api/scraping/meta/route.ts +++ b/app/api/scraping/meta/route.ts @@ -22,11 +22,11 @@ export async function GET(req: Request) { const custom_apiKey = url.searchParams.get("key"); if (!custom_apiKey) { return Response.json( - "API key is required. You can get your API key from your Dashboard-Settings.", + "API key is required. You can get your API key from Dashboard->Settings.", { status: 400, statusText: - "API key is required. You can get your API key from your Dashboard-Settings.", + "API key is required. You can get your API key from Dashboard->Settings.", }, ); } @@ -34,9 +34,10 @@ export async function GET(req: Request) { // Check if the API key is valid const user_apiKey = await checkApiKey(custom_apiKey); if (!user_apiKey?.id) { - return Response.json("Invalid API key", { - status: 403, - statusText: "Invalid API key", + return Response.json("error", { + status: 401, + statusText: + "Invalid API key. You can get your API key from Dashboard->Settings.", }); } diff --git a/app/api/scraping/screenshot/route.ts b/app/api/scraping/screenshot/route.ts index ddc7984..4df6f92 100644 --- a/app/api/scraping/screenshot/route.ts +++ b/app/api/scraping/screenshot/route.ts @@ -34,11 +34,11 @@ export async function GET(req: Request) { const custom_apiKey = url.searchParams.get("key"); if (!custom_apiKey) { return Response.json( - "API key is required. You can get your API key from your Dashboard-Settings.", + "API key is required. You can get your API key from Dashboard->Settings.", { status: 400, statusText: - "API key is required. You can get your API key from your Dashboard-Settings.", + "API key is required. You can get your API key from Dashboard->Settings.", }, ); } @@ -46,9 +46,10 @@ export async function GET(req: Request) { // Check if the API key is valid const user_apiKey = await checkApiKey(custom_apiKey); if (!user_apiKey?.id) { - return Response.json("Invalid API key", { - status: 403, - statusText: "Invalid API key", + return Response.json("error", { + status: 401, + statusText: + "Invalid API key. You can get your API key from Dashboard->Settings.", }); }