Skip to content

Commit 6e36086

Browse files
committed
Merge commit '2ed08bf7856f569c0617e36e6b14a59e4bddbc71' into modernization-with-fixes
* commit '2ed08bf7856f569c0617e36e6b14a59e4bddbc71': fix(search): fix search error not being passed to NotionRenderer properly
2 parents 23706ce + 2ed08bf commit 6e36086

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

lib/search-notion.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@ async function searchNotionImpl(
2020
headers: {
2121
'content-type': 'application/json'
2222
}
23-
})
24-
.then((res) => {
25-
if (res.ok) {
26-
return res
27-
}
23+
}).then((res) => {
24+
if (res.ok) {
25+
return res.json()
26+
}
2827

29-
// convert non-2xx HTTP responses into errors
30-
const error: any = new Error(res.statusText)
31-
error.response = res
32-
return Promise.reject(error)
28+
return new Promise((resolve) => {
29+
res.json().then((json) => {
30+
// convert non-2xx HTTP responses into errors
31+
// react-notion-x expects an "error" key present in the response
32+
// https://github.com/NotionX/react-notion-x/blob/e1f03de6100f2cd33c146eb1c5e67ec4d4afe522/packages/react-notion-x/src/components/search-dialog.tsx#L211
33+
json.error = res.statusText
34+
resolve(json)
35+
})
3336
})
34-
.then((res) => res.json())
35-
36-
// return ky
37-
// .post(api.searchNotion, {
38-
// json: params
39-
// })
40-
// .json()
37+
})
4138
}

pages/api/search-notion.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
1111
const searchParams: types.SearchParams = req.body
1212

1313
console.log('<<< lambda search-notion', searchParams)
14-
const results = await search(searchParams)
15-
console.log('>>> lambda search-notion', results)
14+
try {
15+
const results = await search(searchParams)
16+
console.log('>>> lambda search-notion', results)
1617

17-
res.setHeader(
18-
'Cache-Control',
19-
'public, s-maxage=60, max-age=60, stale-while-revalidate=60'
20-
)
21-
res.status(200).json(results)
18+
res.setHeader(
19+
'Cache-Control',
20+
'public, s-maxage=60, max-age=60, stale-while-revalidate=60'
21+
)
22+
res.status(200).json(results)
23+
} catch (error) {
24+
res.status(error.response.statusCode).send(error)
25+
}
2226
}

0 commit comments

Comments
 (0)