From daf06a32c81786442f2a456d5a97a2425441556f Mon Sep 17 00:00:00 2001 From: oiov Date: Wed, 30 Oct 2024 15:56:33 +0800 Subject: [PATCH] fixup: error statu text --- app/(protected)/dashboard/scrape/meta-scraping.tsx | 7 ++++--- app/api/scraping/meta/route.ts | 12 +++++++----- app/api/scraping/screenshot/route.ts | 5 ++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/(protected)/dashboard/scrape/meta-scraping.tsx b/app/(protected)/dashboard/scrape/meta-scraping.tsx index 2d9d87b..fb68052 100644 --- a/app/(protected)/dashboard/scrape/meta-scraping.tsx +++ b/app/(protected)/dashboard/scrape/meta-scraping.tsx @@ -74,7 +74,8 @@ export default function MetaScraping({ `/api/scraping/meta?url=${protocol}${currentLink}&key=${user.apiKey}`, ); if (!res.ok || res.status !== 200) { - toast.error(res.statusText || "Something went wrong"); + const data = await res.json(); + toast.error(data.statusText); } else { const data = await res.json(); setMetaInfo(data); @@ -89,9 +90,9 @@ export default function MetaScraping({ setIsShoting(true); const payload = `/api/scraping/screenshot?url=${protocol}${currentScreenshotLink}&key=${user.apiKey}`; const res = await fetch(payload); - console.log(res); if (!res.ok || res.status !== 200) { - toast.error(res.statusText || "Something went wrong"); + const data = await res.json(); + toast.error(data.statusText); } 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 06f9370..5e14ae3 100644 --- a/app/api/scraping/meta/route.ts +++ b/app/api/scraping/meta/route.ts @@ -34,11 +34,13 @@ 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("error", { - status: 401, - statusText: - "Invalid API key. You can get your API key from Dashboard->Settings.", - }); + return Response.json( + { + statusText: + "API key is required. You can get your API key from Dashboard->Settings.", + }, + { status: 401 }, + ); } const res = await fetch(link); diff --git a/app/api/scraping/screenshot/route.ts b/app/api/scraping/screenshot/route.ts index 14d61e5..684503b 100644 --- a/app/api/scraping/screenshot/route.ts +++ b/app/api/scraping/screenshot/route.ts @@ -47,12 +47,11 @@ export async function GET(req: Request) { const user_apiKey = await checkApiKey(custom_apiKey); if (!user_apiKey?.id) { return Response.json( - { error: "Invalid API key" }, { - status: 401, statusText: - "Invalid API key. You can get your API key from Dashboard->Settings.", + "API key is required. You can get your API key from Dashboard->Settings.", }, + { status: 401 }, ); }