fixup: error statu text

This commit is contained in:
oiov
2024-10-30 15:56:33 +08:00
parent 027a351fee
commit daf06a32c8
3 changed files with 13 additions and 11 deletions
@@ -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);
+7 -5
View File
@@ -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);
+2 -3
View File
@@ -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 },
);
}