summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pages/api/shop/searchkey.js11
-rw-r--r--src/pages/searchkey/[slug].jsx5
2 files changed, 14 insertions, 2 deletions
diff --git a/src/pages/api/shop/searchkey.js b/src/pages/api/shop/searchkey.js
index f5546a36..51b92baf 100644
--- a/src/pages/api/shop/searchkey.js
+++ b/src/pages/api/shop/searchkey.js
@@ -1,4 +1,6 @@
import axios from 'axios';
+import { notFound } from 'next/navigation';
+import PageNotFound from '../../404';
export default async function handler(req, res) {
const { url = '', page = 1, limit = 30, all } = req.query;
@@ -32,10 +34,15 @@ export default async function handler(req, res) {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
- }
+ },
);
- res.status(200).json(result.data);
+ const solrResponse = result.data;
+ if (solrResponse.response.numFound === 0) {
+ return res.status(404).json({ error: 'Not Found' });
+ } else {
+ res.status(200).json(result.data);
+ }
} catch (error) {
console.error(error?.response?.data || error);
res.status(500).json({ error: 'Internal Server Error' });
diff --git a/src/pages/searchkey/[slug].jsx b/src/pages/searchkey/[slug].jsx
index fbe72dae..06c7252b 100644
--- a/src/pages/searchkey/[slug].jsx
+++ b/src/pages/searchkey/[slug].jsx
@@ -38,6 +38,11 @@ export default function KeywordPage() {
setResult(res?.data?.response?.docs?.[0] || null);
} catch (e) {
+ if (e.response?.status === 404) {
+ route.replace('/404'); // 🔥 redirect ke 404
+ return;
+ }
+
console.error('Fetching searchkey failed:', e);
}
};